Skip to content

Commit

Permalink
Better error message for failing conversion (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
glucaci authored and michaelstaib committed Jun 6, 2019
1 parent 91d1c4f commit 810e581
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Core/Types/Properties/TypeResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Core/Types/Properties/TypeResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -578,4 +578,7 @@ Type: `{0}`</value>
<data name="TypeRegistrar_TypesInconsistent" xml:space="preserve">
<value>Unable to infer or resolve a schema type from the type reference `{0}`.</value>
</data>
<data name="TypeConvertion_ConvertNotSupported" xml:space="preserve">
<value>Unable to convert type from `{0}` to `{1}`</value>
</data>
</root>
7 changes: 6 additions & 1 deletion src/Core/Types/Utilities/TypeConversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using HotChocolate.Properties;

namespace HotChocolate.Utilities
{
Expand Down Expand Up @@ -38,7 +39,11 @@ public object Convert(Type from, Type to, object source)
{
if (!TryConvert(from, to, source, out object converted))
{
throw new NotSupportedException();
throw new NotSupportedException(
string.Format(
TypeResources.TypeConvertion_ConvertNotSupported,
from.Name,
to.Name));
}
return converted;
}
Expand Down

0 comments on commit 810e581

Please sign in to comment.