Skip to content

Commit

Permalink
better exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 11, 2025
1 parent 9fbe98a commit 8b4af64
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/Verify/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ public Target(string extension, Stream data, string? name = null)

if (FileExtensions.IsTextExtension(extension))
{
throw new($"Dont pass a stream for text. If {extension} is not a text extension then add `FileExtensions.RemoveTextExtensions(\"{extension}\")` at initialization; " +
"otherwise use `Target(string extension, string data)` or `Target(string extension, StringBuilder data, string? name)`.");
throw new(
$"""
Don't pass a stream for text.
If {extension} is not a text extension then use `FileExtensions.RemoveTextExtensions(\"{extension}\")` at initialization;
Otherwise use `Target(string extension, string data)` or `Target(string extension, StringBuilder data, string? name)`.
""");
}

Extension = extension;
Expand All @@ -58,8 +62,12 @@ public Target(string extension, StringBuilder data, string? name = null)
Guard.NotEmpty(name);
if (!FileExtensions.IsTextExtension(extension))
{
throw new($"Dont pass a text for a binary extension. If {extension} is a text extension then add `FileExtensions.AddTextExtension(\"{extension}\")` at initialization; " +
"otherwise use `Target(string extension, Stream data, string? name)`.");
throw new(
$"""
Don't pass text for a binary extension.
If {extension} is a text extension then use `FileExtensions.AddTextExtension("{extension}")` at initialization;
Otherwise use `Target(string extension, Stream data, string? name)`.
""");
}

Extension = extension;
Expand All @@ -74,8 +82,12 @@ public Target(string extension, string data, string? name = null)
Guard.NotEmpty(name, nameof(name));
if (!FileExtensions.IsTextExtension(extension))
{
throw new($"Dont pass a text for a binary extension. If {extension} is a text extension then add `FileExtensions.AddTextExtension(\"{extension}\")` at initialization; " +
"otherwise use `Target(string extension, Stream data, string? name)`.");
throw new(
$"""
Don't pass a text for a binary extension.
If {extension} is a text extension then use `FileExtensions.AddTextExtension("{extension}")` at initialization;
Otherwise use `Target(string extension, Stream data, string? name)`.
""");
}

Extension = extension;
Expand Down

0 comments on commit 8b4af64

Please sign in to comment.