From c2fe26d7f84b70dbd852444e039c5669ca20fe97 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Wed, 10 Dec 2025 16:54:00 +0100 Subject: [PATCH] Improve Pandoc process error handling --- app/MindWork AI Studio/Tools/Pandoc.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/MindWork AI Studio/Tools/Pandoc.cs b/app/MindWork AI Studio/Tools/Pandoc.cs index c4bdb462..afce67f9 100644 --- a/app/MindWork AI Studio/Tools/Pandoc.cs +++ b/app/MindWork AI Studio/Tools/Pandoc.cs @@ -49,19 +49,26 @@ public static partial class Pandoc { if (showMessages) await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Help, TB("Was not able to check the Pandoc installation."))); - + LOG.LogInformation("The Pandoc process was not started, it was null"); return new(false, TB("Was not able to check the Pandoc installation."), false, string.Empty, preparedProcess.IsLocal); } - - var output = await process.StandardOutput.ReadToEndAsync(); + + // Read output streams asynchronously while the process runs (prevents deadlock): + var outputTask = process.StandardOutput.ReadToEndAsync(); + var errorTask = process.StandardError.ReadToEndAsync(); + + // Wait for the process to exit AND for streams to be fully read: await process.WaitForExitAsync(); + var output = await outputTask; + var error = await errorTask; + if (process.ExitCode != 0) { if (showMessages) await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Error, TB("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 exited with code {ProcessExitCode}. Error output: '{ErrorText}'", process.ExitCode, error); return new(false, TB("Pandoc is not available on the system or the process had issues."), false, string.Empty, preparedProcess.IsLocal); }