Refine and clarify Pandoc process error messages

This commit is contained in:
Thorsten Sommer 2025-05-30 17:38:19 +02:00
parent e15d16e444
commit fb75480245
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -45,10 +45,10 @@ public static partial class Pandoc
if (process == null) if (process == null)
{ {
if (showMessages) if (showMessages)
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Help, "The pandoc process could not be started.")); await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Help, "Was not able to check the Pandoc installation."));
LOG.LogInformation("The pandoc process was not started, it was null"); LOG.LogInformation("The Pandoc process was not started, it was null");
return new(false, "Was not able to start the pandoc process.", false, string.Empty, preparedProcess.IsLocal); return new(false, "Was not able to check the Pandoc installation.", false, string.Empty, preparedProcess.IsLocal);
} }
var output = await process.StandardOutput.ReadToEndAsync(); var output = await process.StandardOutput.ReadToEndAsync();
@ -56,21 +56,22 @@ public static partial class Pandoc
if (process.ExitCode != 0) if (process.ExitCode != 0)
{ {
if (showMessages) if (showMessages)
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Error, "The pandoc process exited unexpectedly.")); await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Error, "Pandoc is not available on the system or the process had issues."));
LOG.LogError("The pandoc process was exited with code {ProcessExitCode}", process.ExitCode); LOG.LogError("The Pandoc process was exited with code {ProcessExitCode}", process.ExitCode);
return new(false, "Pandoc is not available on the system or the process exited unexpectedly.", false, string.Empty, preparedProcess.IsLocal); return new(false, "Pandoc is not available on the system or the process had issues.", false, string.Empty, preparedProcess.IsLocal);
} }
var versionMatch = PandocCmdRegex().Match(output); var versionMatch = PandocCmdRegex().Match(output);
if (!versionMatch.Success) if (!versionMatch.Success)
{ {
if (showMessages) if (showMessages)
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Terminal, "pandoc --version returned an invalid format.")); await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Terminal, "Was not able to validate the Pandoc installation."));
LOG.LogError("pandoc --version returned an invalid format:\n {Output}", output); LOG.LogError("Pandoc --version returned an invalid format: {Output}", output);
return new(false, "Pandoc is not available on the system or the version could not be parsed.", false, string.Empty, preparedProcess.IsLocal); return new(false, "Was not able to validate the Pandoc installation.", false, string.Empty, preparedProcess.IsLocal);
} }
var versions = versionMatch.Groups[1].Value; var versions = versionMatch.Groups[1].Value;
var installedVersion = Version.Parse(versions); var installedVersion = Version.Parse(versions);
var installedVersionString = installedVersion.ToString(); var installedVersionString = installedVersion.ToString();
@ -78,24 +79,25 @@ public static partial class Pandoc
if (installedVersion >= MINIMUM_REQUIRED_VERSION) if (installedVersion >= MINIMUM_REQUIRED_VERSION)
{ {
if (showMessages) if (showMessages)
await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.CheckCircle, $"Pandoc {installedVersionString} is installed.")); await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.CheckCircle, $"Pandoc v{installedVersionString} is installed."));
LOG.LogInformation("Pandoc v{0} is installed and matches the required version (v{1})", installedVersionString, MINIMUM_REQUIRED_VERSION.ToString());
return new(true, string.Empty, true, installedVersionString, preparedProcess.IsLocal); return new(true, string.Empty, true, installedVersionString, preparedProcess.IsLocal);
} }
if (showMessages) if (showMessages)
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Build, $"Pandoc {installedVersionString} is installed, but it doesn't match the required version ({MINIMUM_REQUIRED_VERSION.ToString()}).")); await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Build, $"Pandoc v{installedVersionString} is installed, but it doesn't match the required version (v{MINIMUM_REQUIRED_VERSION.ToString()})."));
LOG.LogInformation("Pandoc {Installed} is installed, but it does not match the required version ({Requirement})", installedVersionString, MINIMUM_REQUIRED_VERSION.ToString()); LOG.LogWarning("Pandoc v{0} is installed, but it does not match the required version (v{1})", installedVersionString, MINIMUM_REQUIRED_VERSION.ToString());
return new(true, $"Pandoc {installedVersionString} is installed, but it does not match the required version ({MINIMUM_REQUIRED_VERSION.ToString()}).", false, installedVersionString, preparedProcess.IsLocal); return new(true, $"Pandoc v{installedVersionString} is installed, but it does not match the required version (v{MINIMUM_REQUIRED_VERSION.ToString()}).", false, installedVersionString, preparedProcess.IsLocal);
} }
catch (Exception e) catch (Exception e)
{ {
if (showMessages) if (showMessages)
await MessageBus.INSTANCE.SendError(new (@Icons.Material.Filled.AppsOutage, "Pandoc is not installed.")); await MessageBus.INSTANCE.SendError(new (@Icons.Material.Filled.AppsOutage, "It seems that Pandoc is not installed."));
LOG.LogError("Pandoc is not installed and threw an exception: {Message}", e.Message); LOG.LogError("Pandoc is not installed and threw an exception: {0}", e.Message);
return new(false, "Pandoc is not installed or could not be started.", false, string.Empty, false); return new(false, "It seems that Pandoc is not installed.", false, string.Empty, false);
} }
} }
@ -106,9 +108,12 @@ public static partial class Pandoc
/// <returns>None</returns> /// <returns>None</returns>
public static async Task InstallAsync(RustService rustService) public static async Task InstallAsync(RustService rustService)
{ {
var latestVersion = await FetchLatestVersionAsync();
var installDir = await GetPandocDataFolder(rustService); var installDir = await GetPandocDataFolder(rustService);
ClearFolder(installDir); ClearFolder(installDir);
LOG.LogInformation("Trying to install Pandoc v{0} to '{1}'...", latestVersion, installDir);
try try
{ {
if (!Directory.Exists(installDir)) if (!Directory.Exists(installDir))
@ -127,7 +132,7 @@ public static partial class Pandoc
if (!response.IsSuccessStatusCode) if (!response.IsSuccessStatusCode)
{ {
await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.Error, "Pandoc was not installed successfully, because the archive was not found.")); await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.Error, "Pandoc was not installed successfully, because the archive was not found."));
LOG.LogError("Pandoc was not installed, the release archive was not found (status code {StatusCode}): url='{Uri}', message='{Message}'", response.StatusCode, uri, response.RequestMessage); LOG.LogError("Pandoc was not installed successfully, because the archive was not found (status code {0}): url='{1}', message='{2}'", response.StatusCode, uri, response.RequestMessage);
return; return;
} }
@ -149,12 +154,14 @@ public static partial class Pandoc
else else
{ {
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Error, "Pandoc was not installed successfully, because the archive type is unknown.")); await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Error, "Pandoc was not installed successfully, because the archive type is unknown."));
LOG.LogError("Pandoc was not installed, the archive is unknown: url='{Uri}'", uri); LOG.LogError("Pandoc was not installed, the archive is unknown: url='{0}'", uri);
return; return;
} }
File.Delete(pandocTempDownloadFile); File.Delete(pandocTempDownloadFile);
await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.CheckCircle, $"Pandoc {await FetchLatestVersionAsync()} was installed successfully."));
await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.CheckCircle, $"Pandoc v{latestVersion} was installed successfully."));
LOG.LogInformation("Pandoc v{0} was installed successfully.", latestVersion);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -197,7 +204,7 @@ public static partial class Pandoc
var versionMatch = LatestVersionRegex().Match(htmlContent); var versionMatch = LatestVersionRegex().Match(htmlContent);
if (!versionMatch.Success) if (!versionMatch.Success)
{ {
LOG.LogError("The latest version regex returned nothing: {Value}", versionMatch.Groups.ToString()); LOG.LogError("The latest version regex returned nothing: {0}", versionMatch.Groups.ToString());
await MessageBus.INSTANCE.SendWarning(new (Icons.Material.Filled.Warning, $"The latest pandoc version was not found, installing version {FALLBACK_VERSION.ToString()} instead.")); await MessageBus.INSTANCE.SendWarning(new (Icons.Material.Filled.Warning, $"The latest pandoc version was not found, installing version {FALLBACK_VERSION.ToString()} instead."));
return FALLBACK_VERSION.ToString(); return FALLBACK_VERSION.ToString();
} }