Skip to content

Commit

Permalink
Change exception
Browse files Browse the repository at this point in the history
  • Loading branch information
inputfalken committed Jun 15, 2024
1 parent a30d014 commit c876482
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
9 changes: 3 additions & 6 deletions src/DynamoDBGenerator.SourceGenerator/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public static class ConversionStrategy

public const string AssemblyName = "DynamoDBGenerator";
public const string DynamoDBMarshallerFullname = $"{Namespace.AttributesFullName}.{Attribute.DynamoDBMarshaller}";

public const string DynamoDBConverterFullName = $"{AssemblyName}.{Namespace.Options}.{Converter.AttributeValueConverters}";

public static class Namespace
Expand All @@ -47,6 +46,7 @@ public static class Namespace
public const string Converters = "Converters";
public const string Options = "Options";
}

public static class Converter
{
public const string AttributeValueConverters = "AttributeValueConverters";
Expand Down Expand Up @@ -74,10 +74,8 @@ public static class Marshaller
public const string MarshallMethodName = "Marshall";
}


public const string KeyMarshallerImplementationTypeName = "DynamoDBKeyMarshallerDelegator";
public const string IndexKeyMarshallerImplementationTypeName = "IndexDynamoDBMarshallerDelegator";


public static class AttributeValueUtilityFactory
{
Expand All @@ -94,6 +92,7 @@ public static class AttributeValueUtilityFactory
public const string ToLookup = $"{ClassName}.ToLookup";
public const string FromLookup = $"{ClassName}.FromLookup";
}

public static class ExceptionHelper
{
private const string ExceptionHelperClass = "ExceptionHelper";
Expand All @@ -105,9 +104,8 @@ public static class ExceptionHelper
public const string ShouldNeverHappenExceptionMethod = $"{ExceptionHelperClass}.ShouldNeverHappen";
public const string MissMatchedIndexNameExceptionMethod = $"{ExceptionHelperClass}.MissMatchedIndex";
public const string NoDynamoDBKeyAttributesExceptionMethod = $"{ExceptionHelperClass}.NoDynamoDBAttributes";
public const string InvalidTypeRepresentationExceptionMethod = $"{ExceptionHelperClass}.InvalidTypeRepresentation";
}


}

// ReSharper disable once IdentifierTypo
Expand All @@ -133,7 +131,6 @@ public static class Attribute
public const string DynamoDBGlobalSecondaryIndexHashKey = "DynamoDBGlobalSecondaryIndexHashKeyAttribute";
public const string DynamoDBGlobalSecondaryIndexRangeKey = "DynamoDBGlobalSecondaryIndexRangeKeyAttribute";
}

}

public const string NewLine = @"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ internal static IEnumerable<string> RootSignature(MarshallerOptions options, ITy
return $"public {typeName} {methodName}(Dictionary<{nameof(String)}, {Constants.AWSSDK_DynamoDBv2.AttributeValue}> entity)".CreateScope(
"ArgumentNullException.ThrowIfNull(entity);",
options.IsConvertable(typeSymbol) || typeSymbol.TypeIdentifier() is not UnknownType
? "throw new Exception();"
? $"throw {Constants.DynamoDBGenerator.ExceptionHelper.InvalidTypeRepresentationExceptionMethod}(nameof({typeName}));"
: $"return {UnMarshallerClass}.{GetDeserializationMethodName(typeSymbol)}(entity, {MarshallerOptions.FieldReference});"
);
}
Expand Down
7 changes: 6 additions & 1 deletion src/DynamoDBGenerator/Internal/ExceptionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public static InvalidOperationException NoDynamoDBAttributes(string typeName)
{
return new InvalidOperationException($"Could not create keys for type '{typeName}', include DynamoDBKeyAttribute on the correct properties.");
}

public static InvalidOperationException InvalidTypeRepresentation(string typeName)
{
return new InvalidOperationException($"Could not unmarshall the type '{typeName}' from an 'Dictionary<String, AttributeValue>'.");
}

public static Exception ShouldNeverHappen()
{
Expand All @@ -51,4 +56,4 @@ public static ArgumentOutOfRangeException MissMatchedIndex(string paramName, str
return new ArgumentOutOfRangeException(paramName, $"Could not find any index match for value '{value}'.");
}
#pragma warning restore CS1591
}
}

0 comments on commit c876482

Please sign in to comment.