From f8491e61a52689300ca2de74a223cbea2aa155b9 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Wed, 10 Dec 2025 17:29:20 +0100 Subject: [PATCH] Handle missing file attachments in message processing (#587) --- app/MindWork AI Studio/Chat/ContentText.cs | 46 ++++++++++++++-------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/app/MindWork AI Studio/Chat/ContentText.cs b/app/MindWork AI Studio/Chat/ContentText.cs index 09a4e0af..c697a03d 100644 --- a/app/MindWork AI Studio/Chat/ContentText.cs +++ b/app/MindWork AI Studio/Chat/ContentText.cs @@ -156,29 +156,43 @@ public sealed class ContentText : IContent if(this.FileAttachments.Count > 0) { - // Check Pandoc availability once before processing file attachments - var pandocState = await Pandoc.CheckAvailabilityAsync(Program.RUST_SERVICE, showMessages: true, showSuccessMessage: false); + // Filter out files that no longer exist + var existingFiles = this.FileAttachments.Where(File.Exists).ToList(); - if (!pandocState.IsAvailable) - LOGGER.LogWarning("File attachments could not be processed because Pandoc is not available."); - else if (!pandocState.CheckWasSuccessful) - LOGGER.LogWarning("File attachments could not be processed because the Pandoc version check failed."); - else + // Log warning for missing files + var missingFiles = this.FileAttachments.Except(existingFiles).ToList(); + if (missingFiles.Count > 0) + foreach (var missingFile in missingFiles) + LOGGER.LogWarning("File attachment no longer exists and will be skipped: '{MissingFile}'", missingFile); + + // Only proceed if there are existing files + if (existingFiles.Count > 0) { - sb.AppendLine(); - sb.AppendLine("The following files are attached to this message:"); - foreach(var file in this.FileAttachments) + // Check Pandoc availability once before processing file attachments + var pandocState = await Pandoc.CheckAvailabilityAsync(Program.RUST_SERVICE, showMessages: true, showSuccessMessage: false); + + if (!pandocState.IsAvailable) + LOGGER.LogWarning("File attachments could not be processed because Pandoc is not available."); + else if (!pandocState.CheckWasSuccessful) + LOGGER.LogWarning("File attachments could not be processed because the Pandoc version check failed."); + else { sb.AppendLine(); - sb.AppendLine("---------------------------------------"); - sb.AppendLine($"File path: {file}"); - sb.AppendLine("File content:"); - sb.AppendLine("````"); - sb.AppendLine(await Program.RUST_SERVICE.ReadArbitraryFileData(file, int.MaxValue)); - sb.AppendLine("````"); + sb.AppendLine("The following files are attached to this message:"); + foreach(var file in existingFiles) + { + sb.AppendLine(); + sb.AppendLine("---------------------------------------"); + sb.AppendLine($"File path: {file}"); + sb.AppendLine("File content:"); + sb.AppendLine("````"); + sb.AppendLine(await Program.RUST_SERVICE.ReadArbitraryFileData(file, int.MaxValue)); + sb.AppendLine("````"); + } } } } + return sb.ToString(); }