Skip to content

AddTypeConverter<T1, T2> errors result in NotSupportedException but without an inner exception #6385

@stevewgh

Description

@stevewgh

Is there an existing issue for this?

  • I have searched the existing issues

Product

Hot Chocolate

Describe the bug

When using type converters, if the type converter fails then the root cause of the failure is lost and can't be used by the error filter.

The exception is a NotSupportedException but the inner exception is null. The resulting error message is the very generic and unhelpful "Unable to convert type from 'x' to 'y'".

One use case where we would find the route cause useful is within our IError filter where we could check for the inner exception type and then change the error message to something more meaningful or change the error code.

services
  .AddGraphQLServer()
  .AddTypeConverter<T1, T2>(source => throw new CustomException("I want to use this in the error filter below"))
  .AddErrorFilter<MyErrorErrorFilter>();

public class MyErrorErrorFilter : IErrorFilter {
    public IError OnError(IError error)
    {
        if (error.Exception is NotSupportedException { InnerException: CustomException } custom )
        {
            // do something with the custom exception
        }
        return error;
    }
}

Steps to reproduce

  1. Add a type converter which throws an exception
  2. e.g. .AddTypeConverter<T1, T2>(source => throw new CustomException("not good"))
  3. Add an IErrorFilter which tries to use the root cause exception
  4. Observe that the NotSupportedException does not contain the CustomException in the inner exception property

Relevant log output

None.

Additional Context?

I have a PR in progress which contains changes isolated to the DefaultTypeConverter to include the inner exception.
If you give me the thumbs up on this issue I'll try to finish it off ASAP.

Version

13.0.5

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions