Skip to content

Commit

Permalink
Add message to exception when enum conversion fails in Strawberry Sha…
Browse files Browse the repository at this point in the history
  • Loading branch information
jorrit authored Jan 30, 2023
1 parent 6c2b66e commit a7d1279
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ private ICode CreateEnumParsingSwitch(
.New()
.SetReturn()
.SetExpression(serializedValue)
.SetDefaultCase(ExceptionBuilder.Inline(TypeNames.GraphQLClientException));
.SetDefaultCase(ExceptionBuilder.Inline(TypeNames.GraphQLClientException)
.AddArgument($"$\"String value '{{serializedValue}}' can't be converted to enum {descriptor.Name}\""));

foreach (var enumValue in descriptor.Values)
{
Expand All @@ -77,7 +78,8 @@ private ICode CreateEnumFormattingSwitch(
SwitchExpressionBuilder.New()
.SetReturn()
.SetExpression(runtimeValue)
.SetDefaultCase(ExceptionBuilder.Inline(TypeNames.GraphQLClientException));
.SetDefaultCase(ExceptionBuilder.Inline(TypeNames.GraphQLClientException)
.AddArgument($"$\"Enum {descriptor.Name} value '{{runtimeValue}}' can't be converted to string\""));

foreach (var enumValue in descriptor.Values)
{
Expand All @@ -88,4 +90,4 @@ private ICode CreateEnumFormattingSwitch(

return switchExpression;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ public Episode Parse(global::System.String serializedValue)
"NEW_HOPE" => Episode.NewHope,
"EMPIRE" => Episode.Empire,
"JEDI" => Episode.Jedi,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum Episode")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -1174,7 +1174,7 @@ public Episode Parse(global::System.String serializedValue)
Episode.NewHope => "NEW_HOPE",
Episode.Empire => "EMPIRE",
Episode.Jedi => "JEDI",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum Episode value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2854,7 +2854,7 @@ public __TypeKind Parse(global::System.String serializedValue)
"INPUT_OBJECT" => __TypeKind.InputObject,
"LIST" => __TypeKind.List,
"NON_NULL" => __TypeKind.NonNull,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum __TypeKind")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -2869,7 +2869,7 @@ public __TypeKind Parse(global::System.String serializedValue)
__TypeKind.InputObject => "INPUT_OBJECT",
__TypeKind.List => "LIST",
__TypeKind.NonNull => "NON_NULL",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum __TypeKind value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ namespace Foo.Bar
"NEW_HOPE" => Episode.NewHope,
"EMPIRE" => Episode.Empire,
"JEDI" => Episode.Jedi,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum Episode")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -751,7 +751,7 @@ namespace Foo.Bar
Episode.NewHope => "NEW_HOPE",
Episode.Empire => "EMPIRE",
Episode.Jedi => "JEDI",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum Episode value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ namespace Foo.Bar
"MISSING_ARGUMENT" => ErrorCode.MissingArgument,
"INVALID_ARGUMENT" => ErrorCode.InvalidArgument,
"FAILED" => ErrorCode.Failed,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum ErrorCode")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -511,7 +511,7 @@ namespace Foo.Bar
ErrorCode.MissingArgument => "MISSING_ARGUMENT",
ErrorCode.InvalidArgument => "INVALID_ARGUMENT",
ErrorCode.Failed => "FAILED",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum ErrorCode value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ namespace Foo.Bar
"NEW_HOPE" => Episode.NewHope,
"EMPIRE" => Episode.Empire,
"JEDI" => Episode.Jedi,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum Episode")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -293,7 +293,7 @@ namespace Foo.Bar
Episode.NewHope => "NEW_HOPE",
Episode.Empire => "EMPIRE",
Episode.Jedi => "JEDI",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum Episode value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ namespace Foo.Bar
"NEW_HOPE" => Episode.NewHope,
"EMPIRE" => Episode.Empire,
"JEDI" => Episode.Jedi,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum Episode")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -293,7 +293,7 @@ namespace Foo.Bar
Episode.NewHope => "NEW_HOPE",
Episode.Empire => "EMPIRE",
Episode.Jedi => "JEDI",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum Episode value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ namespace Foo.Bar
"NEW_HOPE" => Episode.NewHope,
"EMPIRE" => Episode.Empire,
"JEDI" => Episode.Jedi,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum Episode")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -293,7 +293,7 @@ namespace Foo.Bar
Episode.NewHope => "NEW_HOPE",
Episode.Empire => "EMPIRE",
Episode.Jedi => "JEDI",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum Episode value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ namespace Foo.Bar
"NEW_HOPE" => Episode.NewHope,
"EMPIRE" => Episode.Empire,
"JEDI" => Episode.Jedi,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum Episode")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -347,7 +347,7 @@ namespace Foo.Bar
Episode.NewHope => "NEW_HOPE",
Episode.Empire => "EMPIRE",
Episode.Jedi => "JEDI",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum Episode value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,7 @@ namespace Foo.Bar
{
"INCOMING" => Direction.Incoming,
"OUTGOING" => Direction.Outgoing,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum Direction")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -2597,7 +2597,7 @@ namespace Foo.Bar
{
Direction.Incoming => "INCOMING",
Direction.Outgoing => "OUTGOING",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum Direction value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ namespace Foo.Bar
"EDUCATION" => ExpenseCategory.Education,
"MISCELLANEOUS" => ExpenseCategory.Miscellaneous,
"PERSONAL_CARE" => ExpenseCategory.PersonalCare,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum ExpenseCategory")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -369,7 +369,7 @@ namespace Foo.Bar
ExpenseCategory.Education => "EDUCATION",
ExpenseCategory.Miscellaneous => "MISCELLANEOUS",
ExpenseCategory.PersonalCare => "PERSONAL_CARE",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum ExpenseCategory value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down Expand Up @@ -398,7 +398,7 @@ namespace Foo.Bar
"DEBIT_CARD" => PaymentMethod.DebitCard,
"CREDIT_CARD" => PaymentMethod.CreditCard,
"PAY_PAL" => PaymentMethod.PayPal,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum PaymentMethod")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -410,7 +410,7 @@ namespace Foo.Bar
PaymentMethod.DebitCard => "DEBIT_CARD",
PaymentMethod.CreditCard => "CREDIT_CARD",
PaymentMethod.PayPal => "PAY_PAL",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum PaymentMethod value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ namespace Foo.Bar
"VIEWER" => ProjectUserRoleType.Viewer,
"EDITOR" => ProjectUserRoleType.Editor,
"OWNER" => ProjectUserRoleType.Owner,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum ProjectUserRoleType")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -603,7 +603,7 @@ namespace Foo.Bar
ProjectUserRoleType.Viewer => "VIEWER",
ProjectUserRoleType.Editor => "EDITOR",
ProjectUserRoleType.Owner => "OWNER",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum ProjectUserRoleType value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2855,7 +2855,7 @@ namespace Foo.Bar
"MONTH" => TimeUnit.Month,
"QUARTER" => TimeUnit.Quarter,
"YEAR" => TimeUnit.Year,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum TimeUnit")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -2871,7 +2871,7 @@ namespace Foo.Bar
TimeUnit.Month => "MONTH",
TimeUnit.Quarter => "QUARTER",
TimeUnit.Year => "YEAR",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum TimeUnit value '{runtimeValue}' can't be converted to string")};
}
}

Expand All @@ -2898,7 +2898,7 @@ namespace Foo.Bar
"SUM" => Aggregation.Sum,
"MIN" => Aggregation.Min,
"MAX" => Aggregation.Max,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum Aggregation")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -2909,7 +2909,7 @@ namespace Foo.Bar
Aggregation.Sum => "SUM",
Aggregation.Min => "MIN",
Aggregation.Max => "MAX",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum Aggregation value '{runtimeValue}' can't be converted to string")};
}
}

Expand All @@ -2934,7 +2934,7 @@ namespace Foo.Bar
"NO_VALUE" => DataFlag.NoValue,
"VALID" => DataFlag.Valid,
"MISSING" => DataFlag.Missing,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum DataFlag")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -2944,7 +2944,7 @@ namespace Foo.Bar
DataFlag.NoValue => "NO_VALUE",
DataFlag.Valid => "VALID",
DataFlag.Missing => "MISSING",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum DataFlag value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3333,15 +3333,15 @@ namespace Foo.Bar
return serializedValue switch
{
"people_pkey" => People_constraint.PeoplePkey,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum People_constraint")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
{
return runtimeValue switch
{
People_constraint.PeoplePkey => "people_pkey",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum People_constraint value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down Expand Up @@ -3378,7 +3378,7 @@ namespace Foo.Bar
"firstName" => People_update_column.Firstname,
"id" => People_update_column.Id,
"lastName" => People_update_column.Lastname,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum People_update_column")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -3388,7 +3388,7 @@ namespace Foo.Bar
People_update_column.Firstname => "firstName",
People_update_column.Id => "id",
People_update_column.Lastname => "lastName",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum People_update_column value '{runtimeValue}' can't be converted to string")};
}
}

Expand All @@ -3415,15 +3415,15 @@ namespace Foo.Bar
return serializedValue switch
{
"cars_pkey" => Cars_constraint.CarsPkey,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum Cars_constraint")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
{
return runtimeValue switch
{
Cars_constraint.CarsPkey => "cars_pkey",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum Cars_constraint value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down Expand Up @@ -3460,7 +3460,7 @@ namespace Foo.Bar
"carName" => Cars_update_column.Carname,
"id" => Cars_update_column.Id,
"ownerId" => Cars_update_column.Ownerid,
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"String value '{serializedValue}' can't be converted to enum Cars_update_column")};
}

public global::System.Object Format(global::System.Object? runtimeValue)
Expand All @@ -3470,7 +3470,7 @@ namespace Foo.Bar
Cars_update_column.Carname => "carName",
Cars_update_column.Id => "id",
Cars_update_column.Ownerid => "ownerId",
_ => throw new global::StrawberryShake.GraphQLClientException()};
_ => throw new global::StrawberryShake.GraphQLClientException($"Enum Cars_update_column value '{runtimeValue}' can't be converted to string")};
}
}

Expand Down
Loading

0 comments on commit a7d1279

Please sign in to comment.