Skip to content

Commit 032b944

Browse files
authored
Fix validation error message when parsing function.json (V2) (#2536)
* fix to #2401 * removing unnecessary variable * updating to reflect that both exceptions can be thrown * Moving condition to exception filter, adding more details to enum parsing method
1 parent c707a03 commit 032b944

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/WebJobs.Script/Binding/Extensibility/ScriptBindingContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public ScriptBindingContext(JObject bindingMetadata)
9696
}
9797
else
9898
{
99-
throw new FormatException($"Invalid value specified for binding property '{name}' of enum type {PrettyTypeName(typeof(TEnum))}.");
99+
throw new FormatException($"Error parsing function.json: Invalid value specified for binding property '{name}' of enum type {PrettyTypeName(typeof(TEnum))}.");
100100
}
101101
}
102102

@@ -120,9 +120,9 @@ public ScriptBindingContext(JObject bindingMetadata)
120120
return value.Value<TValue>();
121121
}
122122
}
123-
catch (FormatException e)
123+
catch (Exception e) when (e is InvalidCastException || e is FormatException)
124124
{
125-
throw new FormatException($"Invalid value specified for binding property '{name}' of type {PrettyTypeName(typeof(TValue))}.", e);
125+
throw new FormatException($"Error parsing function.json: Invalid value specified for binding property '{name}' of type {PrettyTypeName(typeof(TValue))}.", e);
126126
}
127127

128128
return defaultValue;

test/WebJobs.Script.Tests/Extensions/ScriptBindingContextTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void GetMetadataValue_ThrowsHelpfulError()
4545

4646
ScriptBindingContext context = new ScriptBindingContext(metadata);
4747
FormatException e = Assert.Throws<FormatException>(() => context.GetMetadataValue<int?>("take"));
48-
Assert.Equal("Invalid value specified for binding property 'take' of type Nullable<Int32>.", e.Message);
48+
Assert.Equal("Error parsing function.json: Invalid value specified for binding property 'take' of type Nullable<Int32>.", e.Message);
4949
}
5050

5151
[Fact]
@@ -102,7 +102,7 @@ public void GetMetadataEnumValue_ThrowsHelpfulError()
102102

103103
ScriptBindingContext context = new ScriptBindingContext(metadata);
104104
FormatException e = Assert.Throws<FormatException>(() => context.GetMetadataEnumValue<Test>("test"));
105-
Assert.Equal("Invalid value specified for binding property 'test' of enum type Test.", e.Message);
105+
Assert.Equal("Error parsing function.json: Invalid value specified for binding property 'test' of enum type Test.", e.Message);
106106
}
107107
}
108108
}

0 commit comments

Comments
 (0)