diff --git a/QuestPDF/Drawing/Exceptions/InitializationException.cs b/QuestPDF/Drawing/Exceptions/InitializationException.cs index 5be5dd2..31cab90 100644 --- a/QuestPDF/Drawing/Exceptions/InitializationException.cs +++ b/QuestPDF/Drawing/Exceptions/InitializationException.cs @@ -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"); + } } } } \ No newline at end of file