Skip to content

Remove exception messages from resource strings #59104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Text;

namespace System.Text.Json.SourceGeneration
{
public sealed partial class JsonSourceGenerator
{
private sealed partial class Emitter
{
/// <summary>
/// Unlike sourcegen warnings, exception messages should not be localized so we keep them in source.
/// </summary>
private static class ExceptionMessages
{
public const string InaccessibleJsonIncludePropertiesNotSupported =
"The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.";

public const string IncompatibleConverterType =
"The converter '{0}' is not compatible with the type '{1}'.";

public const string InitOnlyPropertyDeserializationNotSupported =
"Deserialization of init-only properties is currently not supported in source generation mode.";

public const string InvalidJsonConverterFactoryOutput =
"The converter '{0}' cannot return null or a JsonConverterFactory instance.";

public const string InvalidSerializablePropertyConfiguration =
"Invalid serializable-property configuration specified for type '{0}'. For more information, see 'JsonSourceGenerationMode.Serialization'.";
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private string GenerateForTypeWithUnknownConverter(TypeGenerationSpec typeMetada
}}
else
{{
throw new {InvalidOperationExceptionTypeRef}(string.Format(""{SR.Exception_IncompatibleConverterType}"", converter.GetType(), typeToConvert));
throw new {InvalidOperationExceptionTypeRef}(string.Format(""{ExceptionMessages.IncompatibleConverterType}"", converter.GetType(), typeToConvert));
}}
}}");
}
Expand All @@ -333,7 +333,7 @@ private string GenerateForTypeWithUnknownConverter(TypeGenerationSpec typeMetada
metadataInitSource.Append($@"
if (!converter.CanConvert(typeToConvert))
{{
throw new {InvalidOperationExceptionTypeRef}(string.Format(""{SR.Exception_IncompatibleConverterType}"", converter.GetType(), typeToConvert));
throw new {InvalidOperationExceptionTypeRef}(string.Format(""{ExceptionMessages.IncompatibleConverterType}"", converter.GetType(), typeToConvert));
}}");
}

Expand Down Expand Up @@ -716,21 +716,21 @@ private string GeneratePropMetadataInitFunc(TypeGenerationSpec typeGenerationSpe
{ DefaultIgnoreCondition: JsonIgnoreCondition.Always } => "getter: null",
{ CanUseGetter: true } => $"getter: static (obj) => (({declaringTypeCompilableName})obj).{clrPropertyName}",
{ CanUseGetter: false, HasJsonInclude: true }
=> @$"getter: static (obj) => throw new {InvalidOperationExceptionTypeRef}(""{SR.Format(SR.Exception_InaccessibleJsonIncludePropertiesNotSupported, typeGenerationSpec.Type.Name, memberMetadata.ClrName)}"")",
=> @$"getter: static (obj) => throw new {InvalidOperationExceptionTypeRef}(""{string.Format(ExceptionMessages.InaccessibleJsonIncludePropertiesNotSupported, typeGenerationSpec.Type.Name, memberMetadata.ClrName)}"")",
_ => "getter: null"
};

string setterNamedArg = memberMetadata switch
{
{ DefaultIgnoreCondition: JsonIgnoreCondition.Always } => "setter: null",
{ CanUseSetter: true, IsInitOnlySetter: true }
=> @$"setter: static (obj, value) => throw new {InvalidOperationExceptionTypeRef}(""{SR.Exception_InitOnlyPropertyDeserializationNotSupported}"")",
=> @$"setter: static (obj, value) => throw new {InvalidOperationExceptionTypeRef}(""{ExceptionMessages.InitOnlyPropertyDeserializationNotSupported}"")",
{ CanUseSetter: true } when typeGenerationSpec.IsValueType
=> $@"setter: static (obj, value) => {UnsafeTypeRef}.Unbox<{declaringTypeCompilableName}>(obj).{clrPropertyName} = value!",
{ CanUseSetter: true }
=> @$"setter: static (obj, value) => (({declaringTypeCompilableName})obj).{clrPropertyName} = value!",
{ CanUseSetter: false, HasJsonInclude: true }
=> @$"setter: static (obj, value) => throw new {InvalidOperationExceptionTypeRef}(""{SR.Format(SR.Exception_InaccessibleJsonIncludePropertiesNotSupported, typeGenerationSpec.Type.Name, memberMetadata.ClrName)}"")",
=> @$"setter: static (obj, value) => throw new {InvalidOperationExceptionTypeRef}(""{string.Format(ExceptionMessages.InaccessibleJsonIncludePropertiesNotSupported, typeGenerationSpec.Type.Name, memberMetadata.ClrName)}"")",
_ => "setter: null",
};

Expand Down Expand Up @@ -824,7 +824,7 @@ private string GenerateFastPathFuncForObject(TypeGenerationSpec typeGenSpec)
out Dictionary<string, PropertyGenerationSpec>? serializableProperties,
out bool castingRequiredForProps))
{
string exceptionMessage = SR.Format(SR.Exception_InvalidSerializablePropertyConfiguration, typeRef);
string exceptionMessage = string.Format(ExceptionMessages.InvalidSerializablePropertyConfiguration, typeRef);

return GenerateFastPathFuncForType(
serializeMethodName,
Expand Down Expand Up @@ -1205,7 +1205,7 @@ private string GetFetchLogicForRuntimeSpecifiedCustomConverter()
converter = factory.CreateConverter(type, {OptionsInstanceVariableName});
if (converter == null || converter is {JsonConverterFactoryTypeRef})
{{
throw new {InvalidOperationExceptionTypeRef}(string.Format(""{SR.Exception_InvalidJsonConverterFactoryOutput}"", factory.GetType()));
throw new {InvalidOperationExceptionTypeRef}(string.Format(""{ExceptionMessages.InvalidJsonConverterFactoryOutput}"", factory.GetType()));
}}
}}

Expand Down Expand Up @@ -1236,7 +1236,7 @@ private string GetFetchLogicForGetCustomConverter_TypesWithFactories()
{JsonConverterTypeRef}? converter = factory.CreateConverter(type, {Emitter.OptionsInstanceVariableName});
if (converter == null || converter is {JsonConverterFactoryTypeRef})
{{
throw new {InvalidOperationExceptionTypeRef}(string.Format(""{SR.Exception_InvalidJsonConverterFactoryOutput}"", factory.GetType()));
throw new {InvalidOperationExceptionTypeRef}(string.Format(""{ExceptionMessages.InvalidJsonConverterFactoryOutput}"", factory.GetType()));
}}

return converter;
Expand Down
16 changes: 0 additions & 16 deletions src/libraries/System.Text.Json/gen/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,4 @@
<data name="InaccessibleJsonIncludePropertiesNotSupportedFormat" xml:space="preserve">
<value>The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</value>
</data>
<!-- runtime exception messages -->
<data name="Exception_IncompatibleConverterType" xml:space="preserve">
<value>The converter '{0}' is not compatible with the type '{1}'.</value>
</data>
<data name="Exception_InitOnlyPropertyDeserializationNotSupported" xml:space="preserve">
<value>Deserialization of init-only properties is currently not supported in source generation mode.</value>
</data>
<data name="Exception_InaccessibleJsonIncludePropertiesNotSupported" xml:space="preserve">
<value>The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</value>
</data>
<data name="Exception_InvalidSerializablePropertyConfiguration" xml:space="preserve">
<value>Invalid serializable-property configuration specified for type '{0}'. For more information, see 'JsonSourceGenerationMode.Serialization'.</value>
</data>
<data name="Exception_InvalidJsonConverterFactoryOutput" xml:space="preserve">
<value>The converter '{0}' cannot return null or a JsonConverterFactory instance.</value>
</data>
</root>
25 changes: 0 additions & 25 deletions src/libraries/System.Text.Json/gen/Resources/xlf/Strings.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,6 @@
<target state="translated">Duplicitní název typu</target>
<note />
</trans-unit>
<trans-unit id="Exception_InaccessibleJsonIncludePropertiesNotSupported">
<source>The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</source>
<target state="new">The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</target>
<note />
</trans-unit>
<trans-unit id="Exception_IncompatibleConverterType">
<source>The converter '{0}' is not compatible with the type '{1}'.</source>
<target state="new">The converter '{0}' is not compatible with the type '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InitOnlyPropertyDeserializationNotSupported">
<source>Deserialization of init-only properties is currently not supported in source generation mode.</source>
<target state="new">Deserialization of init-only properties is currently not supported in source generation mode.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InvalidJsonConverterFactoryOutput">
<source>The converter '{0}' cannot return null or a JsonConverterFactory instance.</source>
<target state="new">The converter '{0}' cannot return null or a JsonConverterFactory instance.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InvalidSerializablePropertyConfiguration">
<source>Invalid serializable-property configuration specified for type '{0}'. For more information, see 'JsonSourceGenerationMode.Serialization'.</source>
<target state="new">Invalid serializable-property configuration specified for type '{0}'. For more information, see 'JsonSourceGenerationMode.Serialization'.</target>
<note />
</trans-unit>
<trans-unit id="InaccessibleJsonIncludePropertiesNotSupportedFormat">
<source>The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</source>
<target state="new">The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</target>
Expand Down
25 changes: 0 additions & 25 deletions src/libraries/System.Text.Json/gen/Resources/xlf/Strings.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,6 @@
<target state="translated">Doppelter Typname</target>
<note />
</trans-unit>
<trans-unit id="Exception_InaccessibleJsonIncludePropertiesNotSupported">
<source>The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</source>
<target state="new">The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</target>
<note />
</trans-unit>
<trans-unit id="Exception_IncompatibleConverterType">
<source>The converter '{0}' is not compatible with the type '{1}'.</source>
<target state="new">The converter '{0}' is not compatible with the type '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InitOnlyPropertyDeserializationNotSupported">
<source>Deserialization of init-only properties is currently not supported in source generation mode.</source>
<target state="new">Deserialization of init-only properties is currently not supported in source generation mode.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InvalidJsonConverterFactoryOutput">
<source>The converter '{0}' cannot return null or a JsonConverterFactory instance.</source>
<target state="new">The converter '{0}' cannot return null or a JsonConverterFactory instance.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InvalidSerializablePropertyConfiguration">
<source>Invalid serializable-property configuration specified for type '{0}'. For more information, see 'JsonSourceGenerationMode.Serialization'.</source>
<target state="new">Invalid serializable-property configuration specified for type '{0}'. For more information, see 'JsonSourceGenerationMode.Serialization'.</target>
<note />
</trans-unit>
<trans-unit id="InaccessibleJsonIncludePropertiesNotSupportedFormat">
<source>The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</source>
<target state="new">The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</target>
Expand Down
25 changes: 0 additions & 25 deletions src/libraries/System.Text.Json/gen/Resources/xlf/Strings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,6 @@
<target state="translated">Nombre de tipo duplicado.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InaccessibleJsonIncludePropertiesNotSupported">
<source>The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</source>
<target state="new">The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</target>
<note />
</trans-unit>
<trans-unit id="Exception_IncompatibleConverterType">
<source>The converter '{0}' is not compatible with the type '{1}'.</source>
<target state="new">The converter '{0}' is not compatible with the type '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InitOnlyPropertyDeserializationNotSupported">
<source>Deserialization of init-only properties is currently not supported in source generation mode.</source>
<target state="new">Deserialization of init-only properties is currently not supported in source generation mode.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InvalidJsonConverterFactoryOutput">
<source>The converter '{0}' cannot return null or a JsonConverterFactory instance.</source>
<target state="new">The converter '{0}' cannot return null or a JsonConverterFactory instance.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InvalidSerializablePropertyConfiguration">
<source>Invalid serializable-property configuration specified for type '{0}'. For more information, see 'JsonSourceGenerationMode.Serialization'.</source>
<target state="new">Invalid serializable-property configuration specified for type '{0}'. For more information, see 'JsonSourceGenerationMode.Serialization'.</target>
<note />
</trans-unit>
<trans-unit id="InaccessibleJsonIncludePropertiesNotSupportedFormat">
<source>The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</source>
<target state="new">The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</target>
Expand Down
25 changes: 0 additions & 25 deletions src/libraries/System.Text.Json/gen/Resources/xlf/Strings.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,6 @@
<target state="translated">Nom de type dupliqué.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InaccessibleJsonIncludePropertiesNotSupported">
<source>The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</source>
<target state="new">The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</target>
<note />
</trans-unit>
<trans-unit id="Exception_IncompatibleConverterType">
<source>The converter '{0}' is not compatible with the type '{1}'.</source>
<target state="new">The converter '{0}' is not compatible with the type '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InitOnlyPropertyDeserializationNotSupported">
<source>Deserialization of init-only properties is currently not supported in source generation mode.</source>
<target state="new">Deserialization of init-only properties is currently not supported in source generation mode.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InvalidJsonConverterFactoryOutput">
<source>The converter '{0}' cannot return null or a JsonConverterFactory instance.</source>
<target state="new">The converter '{0}' cannot return null or a JsonConverterFactory instance.</target>
<note />
</trans-unit>
<trans-unit id="Exception_InvalidSerializablePropertyConfiguration">
<source>Invalid serializable-property configuration specified for type '{0}'. For more information, see 'JsonSourceGenerationMode.Serialization'.</source>
<target state="new">Invalid serializable-property configuration specified for type '{0}'. For more information, see 'JsonSourceGenerationMode.Serialization'.</target>
<note />
</trans-unit>
<trans-unit id="InaccessibleJsonIncludePropertiesNotSupportedFormat">
<source>The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</source>
<target state="new">The member '{0}.{1}' has been annotated with the JsonIncludeAttribute but is not visible to the source generator.</target>
Expand Down
Loading