Skip to content

Commit

Permalink
Don't throw exception when casing fail in JavaScript evaluator (#17436)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Sébastien Ros <sebastienros@gmail.com>
  • Loading branch information
MikeAlhayek and sebastienros authored Jan 31, 2025
1 parent fef7ded commit cc37085
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,24 @@ public async Task<T> EvaluateAsync<T>(WorkflowExpression<T> expression, Workflow
return default;
}

var workflowType = workflowContext.WorkflowType;
var directive = $"js:{expression}";
var expressionContext = new WorkflowExecutionScriptContext(workflowContext);
try
{
var workflowType = workflowContext.WorkflowType;
var directive = $"js:{expression}";
var expressionContext = new WorkflowExecutionScriptContext(workflowContext);

await _workflowContextHandlers.InvokeAsync((h, expressionContext) => h.EvaluatingScriptAsync(expressionContext), expressionContext, _logger);

await _workflowContextHandlers.InvokeAsync((h, expressionContext) => h.EvaluatingScriptAsync(expressionContext), expressionContext, _logger);
var methodProviders = scopedMethodProviders.Concat(expressionContext.ScopedMethodProviders);

// Some types cannot be cast (e.g., null to bool), so we need to catch the exception and return the default value.
return (T)_scriptingManager.Evaluate(directive, null, null, methodProviders);
}
catch (Exception ex)
{
_logger.LogError(ex, "An error occurred while evaluating the expression: {Expression}", expression.Expression);
}

var methodProviders = scopedMethodProviders.Concat(expressionContext.ScopedMethodProviders);
return (T)_scriptingManager.Evaluate(directive, null, null, methodProviders);
return default;
}
}

0 comments on commit cc37085

Please sign in to comment.