Skip to content

Commit

Permalink
[pkg/ottl] Improve Statement execution error message (#18733)
Browse files Browse the repository at this point in the history
* Improve Statement execution error message

* Switch log message to warn
  • Loading branch information
TylerHelmuth authored Feb 22, 2023
1 parent c079a8f commit b420247
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/ottl/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Parser[K any] struct {
type Statement[K any] struct {
function Expr[K]
condition BoolExpr[K]
origText string
}

// Execute is a function that will execute the statement's function if the statement's condition is met.
Expand Down Expand Up @@ -134,6 +135,7 @@ func (p *Parser[K]) ParseStatement(statement string) (*Statement[K], error) {
return &Statement[K]{
function: function,
condition: expression,
origText: statement,
}, nil
}

Expand Down Expand Up @@ -201,10 +203,10 @@ func (s *Statements[K]) Execute(ctx context.Context, tCtx K) error {
_, _, err := statement.Execute(ctx, tCtx)
if err != nil {
if s.errorMode == PropagateError {
err = fmt.Errorf("failed to execute statement: %w", err)
err = fmt.Errorf("failed to execute statement: %v, %w", statement.origText, err)
return err
}
s.telemetrySettings.Logger.Error("failed to execute statement", zap.Error(err))
s.telemetrySettings.Logger.Warn("failed to execute statement", zap.Error(err), zap.String("statement", statement.origText))
}
}
return nil
Expand Down

0 comments on commit b420247

Please sign in to comment.