From cb97489787cc7879bafe4d4ee530411e471aae6d Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 14 Apr 2026 18:10:02 +0800 Subject: [PATCH] feat(attachment_processor): enhance error handling and content formatting for attachments - Improved error handling in the attachment processing logic by providing detailed XML-like error messages for text, audio, and document processing failures. - Updated the audio file content format to use XML tags for better structure, replacing the previous placeholder format. This update enhances the clarity of error reporting and improves the overall structure of attachment content. --- internal/handler/session/attachment_processor.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/handler/session/attachment_processor.go b/internal/handler/session/attachment_processor.go index 28dcda65..33254a1c 100644 --- a/internal/handler/session/attachment_processor.go +++ b/internal/handler/session/attachment_processor.go @@ -98,18 +98,22 @@ func (p *AttachmentProcessor) ProcessAttachment( if p.isTextFile(ext) { if err := p.processTextFile(ctx, data, attachment); err != nil { logger.Warnf(ctx, "text file processing failed: %v", err) + attachment.Content = fmt.Sprintf("Failed to process text file
%v
", err) } } else if docparser.IsAudioFormat(ext) { if err := p.processAudioFile(ctx, data, baseName, attachment, asrModelID); err != nil { logger.Warnf(ctx, "audio transcription failed: %v, keeping placeholder", err) + attachment.Content = fmt.Sprintf("Failed to transcribe audio file
%v
", err) } } else if docparser.IsSimpleFormat(ext) { if err := p.processWithDocParser(ctx, data, baseName, ext, attachment, tenantID); err != nil { logger.Warnf(ctx, "SimpleFormatReader failed: %v", err) + attachment.Content = fmt.Sprintf("Failed to parse document
%v
", err) } } else { if err := p.processWithDocumentReader(ctx, data, baseName, ext, attachment, tenantID); err != nil { logger.Warnf(ctx, "DocumentReader failed: %v, keeping metadata only", err) + attachment.Content = fmt.Sprintf("Failed to read document
%v
", err) } } @@ -194,7 +198,7 @@ func (p *AttachmentProcessor) processAudioFile( asrModelID string, ) error { if asrModelID == "" || p.modelService == nil { - attachment.Content = fmt.Sprintf("[audio file: %s]", fileName) + attachment.Content = fmt.Sprintf("", fileName) logger.Infof(ctx, "no ASR model configured, keeping audio placeholder") return nil }