Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 20 additions & 1 deletion src/DotNetWorker/Context/Features/DefaultModelBindingFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Azure.Functions.Worker.Converters;
using Microsoft.Azure.Functions.Worker.Definition;
using Microsoft.Azure.Functions.Worker.Diagnostics.Exceptions;

namespace Microsoft.Azure.Functions.Worker.Context.Features
{
Expand Down Expand Up @@ -31,6 +34,7 @@ public DefaultModelBindingFeature(IEnumerable<IConverter> converters)
_parameterValues = new object?[context.FunctionDefinition.Parameters.Length];
_inputBound = true;

List<string>? errors = null;
for (int i = 0; i < _parameterValues.Length; i++)
{
FunctionParameter param = context.FunctionDefinition.Parameters[i];
Expand All @@ -48,8 +52,23 @@ public DefaultModelBindingFeature(IEnumerable<IConverter> converters)
if (TryConvert(converterContext, out object? target))
{
_parameterValues[i] = target;
continue;
}
else if (source is not null)
{
// Don't initialize this list unless we have to
if (errors is null)
{
errors = new List<string>();
}

errors.Add($"Cannot convert input parameter '{param.Name}' to type '{param.Type.FullName}' from type '{source.GetType().FullName}'.");
}
}

// found errors
if (errors is not null)
{
throw new FunctionInputConverterException($"Error converting {errors.Count} input parameters for Function '{context.FunctionDefinition.Name}': {string.Join(" ", errors)}");
}

return _parameterValues;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Azure.Functions.Worker.Diagnostics.Exceptions
{
internal class FunctionInputConverterException : FunctionWorkerException
{
internal FunctionInputConverterException(string message) : base(message) { }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have a property for the function name?

internal FunctionInputConverterException(string message, Exception innerException) : base(message, innerException) { }
}
}
18 changes: 18 additions & 0 deletions src/DotNetWorker/Diagnostics/Exceptions/FunctionWorkerException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Azure.Functions.Worker.Diagnostics
{
/// <summary>
/// Internal exception that is surfaced to the user
/// </summary>
internal class FunctionWorkerException : Exception
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you defining this to serve as the base for worker exceptions?

{
internal FunctionWorkerException(string message) : base(message) { }

internal FunctionWorkerException(string message, Exception innerException) : base(message, innerException) { }
}
}