@@ -156,29 +156,43 @@ public async Task<string> PrepareContentForAI()
156156
157157 if ( this . FileAttachments . Count > 0 )
158158 {
159- // Check Pandoc availability once before processing file attachments
160- var pandocState = await Pandoc . CheckAvailabilityAsync ( Program . RUST_SERVICE , showMessages : true , showSuccessMessage : false ) ;
161-
162- if ( ! pandocState . IsAvailable )
163- LOGGER . LogWarning ( "File attachments could not be processed because Pandoc is not available." ) ;
164- else if ( ! pandocState . CheckWasSuccessful )
165- LOGGER . LogWarning ( "File attachments could not be processed because the Pandoc version check failed." ) ;
166- else
159+ // Filter out files that no longer exist
160+ var existingFiles = this . FileAttachments . Where ( File . Exists ) . ToList ( ) ;
161+
162+ // Log warning for missing files
163+ var missingFiles = this . FileAttachments . Except ( existingFiles ) . ToList ( ) ;
164+ if ( missingFiles . Count > 0 )
165+ foreach ( var missingFile in missingFiles )
166+ LOGGER . LogWarning ( "File attachment no longer exists and will be skipped: '{MissingFile}'" , missingFile ) ;
167+
168+ // Only proceed if there are existing files
169+ if ( existingFiles . Count > 0 )
167170 {
168- sb . AppendLine ( ) ;
169- sb . AppendLine ( "The following files are attached to this message:" ) ;
170- foreach ( var file in this . FileAttachments )
171+ // Check Pandoc availability once before processing file attachments
172+ var pandocState = await Pandoc . CheckAvailabilityAsync ( Program . RUST_SERVICE , showMessages : true , showSuccessMessage : false ) ;
173+
174+ if ( ! pandocState . IsAvailable )
175+ LOGGER . LogWarning ( "File attachments could not be processed because Pandoc is not available." ) ;
176+ else if ( ! pandocState . CheckWasSuccessful )
177+ LOGGER . LogWarning ( "File attachments could not be processed because the Pandoc version check failed." ) ;
178+ else
171179 {
172180 sb . AppendLine ( ) ;
173- sb . AppendLine ( "---------------------------------------" ) ;
174- sb . AppendLine ( $ "File path: { file } ") ;
175- sb . AppendLine ( "File content:" ) ;
176- sb . AppendLine ( "````" ) ;
177- sb . AppendLine ( await Program . RUST_SERVICE . ReadArbitraryFileData ( file , int . MaxValue ) ) ;
178- sb . AppendLine ( "````" ) ;
181+ sb . AppendLine ( "The following files are attached to this message:" ) ;
182+ foreach ( var file in existingFiles )
183+ {
184+ sb . AppendLine ( ) ;
185+ sb . AppendLine ( "---------------------------------------" ) ;
186+ sb . AppendLine ( $ "File path: { file } ") ;
187+ sb . AppendLine ( "File content:" ) ;
188+ sb . AppendLine ( "````" ) ;
189+ sb . AppendLine ( await Program . RUST_SERVICE . ReadArbitraryFileData ( file , int . MaxValue ) ) ;
190+ sb . AppendLine ( "````" ) ;
191+ }
179192 }
180193 }
181194 }
195+
182196 return sb . ToString ( ) ;
183197 }
184198
0 commit comments