Skip to content
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

Don't throw exception when casing fail in JavaScript evaluator #17436

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}