Improved exception messages
This commit is contained in:
Родитель
d740d67a64
Коммит
b87e8d5d4e
|
@ -4,17 +4,33 @@ namespace QuestPDF.Drawing.Exceptions
|
|||
{
|
||||
public class InitializationException : Exception
|
||||
{
|
||||
internal InitializationException(string documentType, Exception innerException) : base(CreateMessage(documentType), innerException)
|
||||
internal InitializationException(string documentType, Exception innerException) : base(CreateMessage(documentType, innerException.Message), innerException)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private static string CreateMessage(string documentType)
|
||||
private static string CreateMessage(string documentType, string innerExceptionMessage)
|
||||
{
|
||||
return $"Cannot create the {documentType} document using the SkiaSharp library. " +
|
||||
$"This exception usually means that, on your operating system where you run the application, SkiaSharp requires installing additional dependencies. " +
|
||||
$"Such dependencies are available as additional nuget packages, for example SkiaSharp.NativeAssets.Linux. " +
|
||||
$"Please refer to the SkiaSharp documentation for more details.";
|
||||
var (libraryName, nugetConvention) = GetLibraryName();
|
||||
|
||||
return $"Cannot create the {documentType} document using the {libraryName} library. " +
|
||||
$"This exception usually means that, on your operating system where you run the application, {libraryName} requires installing additional dependencies. " +
|
||||
$"Such dependencies are available as additional nuget packages, for example {nugetConvention}.Linux. " +
|
||||
$"Some operating systems may require installing multiple nugets, e.g. MacOS may need both {nugetConvention}.macOS and {nugetConvention}.Linux." +
|
||||
$"Please refer to the {libraryName} documentation for more details. " +
|
||||
$"Also, please consult the inner exception that has been originally thrown by the dependency library.";
|
||||
|
||||
(string GetLibraryName, string nugetConvention) GetLibraryName()
|
||||
{
|
||||
if (innerExceptionMessage.Contains("libSkiaSharp"))
|
||||
return ("SkiaSharp", "SkiaSharp.NativeAssets.Linux");
|
||||
|
||||
if (innerExceptionMessage.Contains("libHarfBuzzSharp"))
|
||||
return ("HarfBuzzSharp", "HarfBuzzSharp.NativeAssets");
|
||||
|
||||
// default
|
||||
return ("SkiaSharp-related", "*.NativeAssets.Linux");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче