Skip to content

Commit d5c9d8e

Browse files
committed
Return Error When Expression Can't Be Parsed
Update exprConverter function to return an error if the Expr expression can't be parsed so it can be handled by the caller.
1 parent ac79353 commit d5c9d8e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

execution.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ func (e *Execution) ExecuteContext(ctx context.Context) (force.JobInfo, error) {
9999
}
100100
}
101101
if e.Expr != "" {
102-
e.Converter = exprConverter(e.Expr, apexContext)
102+
e.Converter, err = exprConverter(e.Expr, apexContext)
103+
if err != nil {
104+
return result.JobInfo, fmt.Errorf("Expr error: %w", err)
105+
}
103106
} else if e.Converter == nil {
104107
return result.JobInfo, fmt.Errorf("Expr or Converter must be defined")
105108
}

expr.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,14 @@ func exprFunctions() []expr.Option {
211211
return exprFunctions
212212
}
213213

214-
func exprConverter(expression string, context any) func(force.ForceRecord) []force.ForceRecord {
214+
func exprConverter(expression string, context any) (func(force.ForceRecord) []force.ForceRecord, error) {
215215
env := Env{
216216
"record": force.ForceRecord{},
217217
"apex": context,
218218
}
219219
program, err := expr.Compile(expression, append(exprFunctions(), expr.Env(env))...)
220220
if err != nil {
221-
log.Fatalln("Invalid expression:", err)
221+
return nil, fmt.Errorf("Invalid expression: %w", err)
222222
}
223223
converter := func(record force.ForceRecord) []force.ForceRecord {
224224
env := Env{
@@ -245,5 +245,5 @@ func exprConverter(expression string, context any) func(force.ForceRecord) []for
245245
log.Warnln("Unexpected value. It should be a map or array or maps. Got", out)
246246
return []force.ForceRecord{}
247247
}
248-
return converter
248+
return converter, nil
249249
}

0 commit comments

Comments
 (0)