mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
More raw string literals
This commit is contained in:
@@ -73,9 +73,10 @@ internal class AnalyzerAssertions : ReferenceTypeAssertions<DiagnosticAnalyzer,
|
||||
if (compilationErrors.Any())
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Failed to compile code." +
|
||||
Environment.NewLine +
|
||||
string.Join(Environment.NewLine, compilationErrors.Select(e => e.ToString()))
|
||||
$"""
|
||||
Failed to compile code.
|
||||
{string.Join(Environment.NewLine, compilationErrors.Select(e => e.ToString()))}
|
||||
"""
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -77,9 +77,10 @@ internal static class DynamicCommandBuilder
|
||||
if (compilationErrors.Any())
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Failed to compile code." +
|
||||
Environment.NewLine +
|
||||
string.Join(Environment.NewLine, compilationErrors.Select(e => e.ToString()))
|
||||
$"""
|
||||
Failed to compile code.
|
||||
{string.Join(Environment.NewLine, compilationErrors.Select(e => e.ToString()))}
|
||||
"""
|
||||
);
|
||||
}
|
||||
|
||||
@@ -95,9 +96,10 @@ internal static class DynamicCommandBuilder
|
||||
if (emitErrors.Any())
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Failed to emit code." +
|
||||
Environment.NewLine +
|
||||
string.Join(Environment.NewLine, emitErrors.Select(e => e.ToString()))
|
||||
$"""
|
||||
Failed to emit code.
|
||||
{string.Join(Environment.NewLine, emitErrors.Select(e => e.ToString()))}
|
||||
"""
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -99,11 +99,11 @@ internal class CommandBinder
|
||||
}
|
||||
|
||||
throw CliFxException.InternalError(
|
||||
$"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has an unsupported underlying property type." +
|
||||
Environment.NewLine +
|
||||
$"There is no known way to convert a string value into an instance of type `{targetType.FullName}`." +
|
||||
Environment.NewLine +
|
||||
"To fix this, either change the property to use a supported type or configure a custom converter."
|
||||
$"""
|
||||
{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has an unsupported underlying property type.
|
||||
There is no known way to convert a string value into an instance of type `{targetType.FullName}`
|
||||
To fix this, either change the property to use a supported type or configure a custom converter.
|
||||
"""
|
||||
);
|
||||
}
|
||||
|
||||
@@ -133,11 +133,11 @@ internal class CommandBinder
|
||||
}
|
||||
|
||||
throw CliFxException.InternalError(
|
||||
$"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has an unsupported underlying property type." +
|
||||
Environment.NewLine +
|
||||
$"There is no known way to convert an array of `{targetElementType.FullName}` into an instance of type `{targetEnumerableType.FullName}`." +
|
||||
Environment.NewLine +
|
||||
"To fix this, change the property to use a type which can be assigned from an array or a type that has a constructor which accepts an array."
|
||||
$"""
|
||||
{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has an unsupported underlying property type.
|
||||
There is no known way to convert an array of `{targetElementType.FullName}` into an instance of type `{targetEnumerableType.FullName}`.
|
||||
To fix this, change the property to use a type which can be assigned from an array or a type that has a constructor which accepts an array.
|
||||
"""
|
||||
);
|
||||
}
|
||||
|
||||
@@ -169,20 +169,21 @@ internal class CommandBinder
|
||||
: ex.Message;
|
||||
|
||||
throw CliFxException.UserError(
|
||||
$"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} cannot be set from the provided argument(s):" +
|
||||
Environment.NewLine +
|
||||
rawValues.Select(v => '<' + v + '>').JoinToString(" ") +
|
||||
Environment.NewLine +
|
||||
$"Error: {errorMessage}",
|
||||
$"""
|
||||
{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} cannot be set from the provided argument(s):
|
||||
{rawValues.Select(v => '<' + v + '>').JoinToString(" ")}
|
||||
Error: {errorMessage}
|
||||
""",
|
||||
ex
|
||||
);
|
||||
}
|
||||
|
||||
// Mismatch (scalar but too many values)
|
||||
throw CliFxException.UserError(
|
||||
$"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} expects a single argument, but provided with multiple:" +
|
||||
Environment.NewLine +
|
||||
rawValues.Select(v => '<' + v + '>').JoinToString(" ")
|
||||
$"""
|
||||
{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} expects a single argument, but provided with multiple:
|
||||
{rawValues.Select(v => '<' + v + '>').JoinToString(" ")}
|
||||
"""
|
||||
);
|
||||
}
|
||||
|
||||
@@ -202,11 +203,11 @@ internal class CommandBinder
|
||||
if (errors.Any())
|
||||
{
|
||||
throw CliFxException.UserError(
|
||||
$"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has been provided with an invalid value." +
|
||||
Environment.NewLine +
|
||||
"Error(s):" +
|
||||
Environment.NewLine +
|
||||
errors.Select(e => "- " + e.Message).JoinToString(Environment.NewLine)
|
||||
$"""
|
||||
{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has been provided with an invalid value.
|
||||
Error(s):
|
||||
{errors.Select(e => "- " + e.Message).JoinToString(Environment.NewLine)}
|
||||
"""
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -264,22 +265,20 @@ internal class CommandBinder
|
||||
if (remainingParameterInputs.Any())
|
||||
{
|
||||
throw CliFxException.UserError(
|
||||
"Unexpected parameter(s):" +
|
||||
Environment.NewLine +
|
||||
remainingParameterInputs
|
||||
.Select(p => p.GetFormattedIdentifier())
|
||||
.JoinToString(" ")
|
||||
$"""
|
||||
Unexpected parameter(s):
|
||||
{remainingParameterInputs.Select(p => p.GetFormattedIdentifier()).JoinToString(" ")}
|
||||
"""
|
||||
);
|
||||
}
|
||||
|
||||
if (remainingRequiredParameterSchemas.Any())
|
||||
{
|
||||
throw CliFxException.UserError(
|
||||
"Missing required parameter(s):" +
|
||||
Environment.NewLine +
|
||||
remainingRequiredParameterSchemas
|
||||
.Select(p => p.GetFormattedIdentifier())
|
||||
.JoinToString(" ")
|
||||
$"""
|
||||
Missing required parameter(s):
|
||||
{remainingRequiredParameterSchemas.Select(p => p.GetFormattedIdentifier()).JoinToString(" ")}
|
||||
"""
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -337,22 +336,20 @@ internal class CommandBinder
|
||||
if (remainingOptionInputs.Any())
|
||||
{
|
||||
throw CliFxException.UserError(
|
||||
"Unrecognized option(s):" +
|
||||
Environment.NewLine +
|
||||
remainingOptionInputs
|
||||
.Select(o => o.GetFormattedIdentifier())
|
||||
.JoinToString(", ")
|
||||
$"""
|
||||
Unrecognized option(s):
|
||||
{remainingOptionInputs.Select(o => o.GetFormattedIdentifier()).JoinToString(", ")}
|
||||
"""
|
||||
);
|
||||
}
|
||||
|
||||
if (remainingRequiredOptionSchemas.Any())
|
||||
{
|
||||
throw CliFxException.UserError(
|
||||
"Missing required option(s):" +
|
||||
Environment.NewLine +
|
||||
remainingRequiredOptionSchemas
|
||||
.Select(o => o.GetFormattedIdentifier())
|
||||
.JoinToString(", ")
|
||||
$"""
|
||||
Missing required option(s):
|
||||
{remainingRequiredOptionSchemas.Select(o => o.GetFormattedIdentifier()).JoinToString(", ")}
|
||||
"""
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ public class DefaultTypeActivator : ITypeActivator
|
||||
catch (MemberAccessException ex)
|
||||
{
|
||||
throw CliFxException.InternalError(
|
||||
$"Failed to create an instance of type `{type.FullName}`, could not access the constructor." +
|
||||
Environment.NewLine +
|
||||
"Default type activator is only capable of instantiating a type if it has a public parameterless constructor." +
|
||||
Environment.NewLine +
|
||||
"To fix this, either add a parameterless constructor to the type or configure a custom activator for the application.",
|
||||
$"""
|
||||
Failed to create an instance of type `{type.FullName}`, could not access the constructor.
|
||||
Default type activator is only capable of instantiating a type if it has a public parameterless constructor.
|
||||
To fix this, either add a parameterless constructor to the type or configure a custom activator for the application.
|
||||
""",
|
||||
ex
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ public class DelegateTypeActivator : ITypeActivator
|
||||
if (instance is null)
|
||||
{
|
||||
throw CliFxException.InternalError(
|
||||
$"Failed to create an instance of type `{type.FullName}`, received <null> instead." +
|
||||
Environment.NewLine +
|
||||
"To fix this, ensure that the provided type activator is configured correctly, as it's not expected to return <null>." +
|
||||
Environment.NewLine +
|
||||
"If you are relying on a dependency container, this error may indicate that the specified type has not been registered."
|
||||
$"""
|
||||
Failed to create an instance of type `{type.FullName}`, received <null> instead.
|
||||
To fix this, ensure that the provided type activator is configured correctly, as it's not expected to return <null>.
|
||||
If you are relying on a dependency container, this error may indicate that the specified type has not been registered.
|
||||
"""
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,15 +129,13 @@ internal partial class CommandSchema
|
||||
if (schema is null)
|
||||
{
|
||||
throw CliFxException.InternalError(
|
||||
$"Type `{type.FullName}` is not a valid command type." +
|
||||
Environment.NewLine +
|
||||
"In order to be a valid command type, it must:" +
|
||||
Environment.NewLine +
|
||||
$"- Implement `{typeof(ICommand).FullName}`" +
|
||||
Environment.NewLine +
|
||||
$"- Be annotated with `{typeof(CommandAttribute).FullName}`" +
|
||||
Environment.NewLine +
|
||||
"- Not be an abstract class"
|
||||
$"""
|
||||
Type `{type.FullName}` is not a valid command type.
|
||||
In order to be a valid command type, it must:
|
||||
- Implement `{typeof(ICommand).FullName}`
|
||||
- Be annotated with `{typeof(CommandAttribute).FullName}`
|
||||
- Not be an abstract class
|
||||
"""
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,9 +96,10 @@ internal partial class StackFrame
|
||||
// If parsing fails, we include the original stacktrace in the
|
||||
// exception so that it's shown to the user.
|
||||
throw new FormatException(
|
||||
"Could not parse stacktrace:" +
|
||||
Environment.NewLine +
|
||||
stackTrace
|
||||
$"""
|
||||
Could not parse stacktrace:
|
||||
{stackTrace}
|
||||
"""
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user