Skip to content

[pkg/ottl] Break lambda arity validation into its own function#49421

Open
evan-bradley wants to merge 5 commits into
open-telemetry:mainfrom
evan-bradley:ottl-lambda-arity-validation
Open

[pkg/ottl] Break lambda arity validation into its own function#49421
evan-bradley wants to merge 5 commits into
open-telemetry:mainfrom
evan-bradley:ottl-lambda-arity-validation

Conversation

@evan-bradley

Copy link
Copy Markdown
Contributor

Description

Follow up from #49184 (comment).

Authorship

  • I, a human, wrote this pull request description myself.

Comment thread .chloggen/ottl-lambda-arity-validation.yaml Outdated
Comment thread pkg/ottl/lambda.go Outdated
Comment thread pkg/ottl/lambda.go
if len(l.formals) != arity {
return nil, fmt.Errorf("lambda expects exactly %d argument(s), got %d", arity, len(l.formals))
}
func (l *LambdaExpression[K]) Activate(ctx context.Context) (*LambdaActivation[K], error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the error if a function calls activate with the wrong parity? Will it panic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't panic, you have one of two things happen:

  1. If there are more arguments than parameters, you'll get an error returned when you try to bind an argument that doesn't have a defined parameter.
  2. If there are fewer arguments than parameters, some parameters are not bound and are essentially nil from my rudimentary testing.

If we're really concerned about ValidateArity not being called before Activate, we could include a flag on the lambda expression to check that ValidateArity has been called.

@edmocosta edmocosta Jul 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're really concerned about ValidateArity not being called before Activate, we could include a flag on the lambda expression to check that ValidateArity has been called.

I'd add this validation to ensure usages are consistent and all functions implementations are correct.
If for some reason the function do not to validate it, Eval((a, b, c) => a, [1, 2]) for example, would be accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants