Skip to content

Commit 05a3196

Browse files
baywetCopilot
andauthored
fix(dotnet): align expression failure diagnostics (#9456)
Co-authored-by: Copilot <[email protected]> Copilot-Session: 0124bc10-e891-43eb-a3e1-6d747bc078d0
1 parent ba4f6b3 commit 05a3196

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/PowerFx/WorkflowExpressionEngine.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,10 @@ private EvaluationResult<FormulaValue> EvaluateScope(ExpressionBase expression)
331331

332332
if (result is ErrorValue errorValue)
333333
{
334-
throw new DeclarativeActionException(errorValue.Format());
334+
throw new DeclarativeActionException(
335+
this.GetSensitivity(expression) == SensitivityLevel.Sensitive
336+
? "Expression evaluation failed for a sensitive value."
337+
: errorValue.Format());
335338
}
336339

337340
return new(result, this.GetSensitivity(expression));

‎dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/PowerFx/WorkflowExpressionEngineTests.cs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,44 @@ public WorkflowExpressionEngineTests(ITestOutputHelper output)
4444
this.State.Bind();
4545
}
4646

47+
[Theory]
48+
[InlineData("Value(Env.Setting)", VariableScopeNames.Environment)]
49+
[InlineData("Error(Env.Setting)", VariableScopeNames.Environment)]
50+
[InlineData("Error({Kind: ErrorKind.Custom, Message: Local.Setting})", VariableScopeNames.Local)]
51+
public void ExpressionErrorOmitsSensitiveInput(string expression, string scope)
52+
{
53+
// Arrange
54+
const string Value = "sample-setting";
55+
this.State.Set("Setting", FormulaValue.New(Value), scope, SensitivityLevel.Sensitive);
56+
this.State.Bind();
57+
58+
// Act
59+
DeclarativeActionException exception = Assert.Throws<DeclarativeActionException>(
60+
() => this.State.Evaluator.GetValue(ValueExpression.Expression(expression)));
61+
62+
// Assert
63+
Assert.DoesNotContain(Value, exception.ToString(), StringComparison.Ordinal);
64+
Assert.Null(exception.InnerException);
65+
}
66+
67+
[Theory]
68+
[InlineData("Value(Local.Setting)")]
69+
[InlineData("Error(Local.Setting)")]
70+
public void ExpressionErrorPreservesNonSensitiveInput(string expression)
71+
{
72+
// Arrange
73+
const string Value = "sample-setting";
74+
this.State.Set("Setting", FormulaValue.New(Value), VariableScopeNames.Local);
75+
this.State.Bind();
76+
77+
// Act
78+
DeclarativeActionException exception = Assert.Throws<DeclarativeActionException>(
79+
() => this.State.Evaluator.GetValue(ValueExpression.Expression(expression)));
80+
81+
// Assert
82+
Assert.Contains(Value, exception.Message, StringComparison.Ordinal);
83+
}
84+
4785
#region BoolExpression Tests
4886

4987
[Fact]

0 commit comments

Comments
 (0)