-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pkg/ottl] Update ExprFunc and boolExpressionEvaluator to return an error #15649
[pkg/ottl] Update ExprFunc and boolExpressionEvaluator to return an error #15649
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change overall looks good but there's lots of places we're ignoring the returned error, both in test and functional components (I've tagged some but there were a lot). We should check the error for nils, as the structure for checking shouldn't change.
@MikeGoldsmith I'll update the tests to be more rigorous and the functions to return their errors, but the calling function, |
If you do this change, I would suggest to change ExprFunc to an interface type Expr[K any] interface {
func Eval(ctx context.Context, tCtx K) (any, error)
}
type ExprFunc[K any] func(ctx context.Context, tCtx K) (interface{}, error)
func (f ExprFunc[K]) Eval(ctx context.Context, tCtx K) {
return f(ctx, tCtx)
} This way in the future we can have optional interfaces that these instances can implement and based on that can extend the capabilities. With the current type Another option that allows extension is to have a struct: type Expr[K any] struct {
EvalFunc[K]
}
func (e Expr[K]) Eval(ctx context.Context, tCtx K) {
return e.EvalFunc(ctx, tCtx)
}
type EvalFunc[K any] func(ctx context.Context, tCtx K) (interface{}, error) |
@bogdandrutu this request is being tracked via #14713, do you want to do that as part of this PR or can it be its own? |
@TylerHelmuth I think at least we should also add "context.Context" to the func :) since we touch that signature. We can do a separate one for the interface/struct. |
@bogdandrutu we don't have a use case yet for passing |
In other words we should pass context almost every time in golang :) We can do a separate PR for sure, but it should be done. |
@bogdandrutu is the claim that any function that accepts |
Not "every". But in 90% of the cases yes :) |
@bogdandrutu ok, I will implement that in a later PR |
@evan-bradley @kentquirk please review. |
…rror (open-telemetry#15649) * Update ExprFunc to return an error * fix dependent processors * Add changelog entry * Fix lint * Fix lint * Apply feedback * Add error handling all the way through
Description:
Changes
ExprFunc
,Get
andSet
. This allows errors from contexts to be propagated upward to a place where they can be better handled.This PR only adds the capability to return errors. It does not update any error handling.
Link to tracking Issue:
Related to #13690
Testing:
Updated unit tests