{"record":{"id":"fcf515f2672af887","repo":"Tencent/WeKnora","slug":"attachment-s-failed-to-parse-s","errorCode":null,"errorMessage":"attachment %s failed to parse: %s","messagePattern":"attachment (.+?) failed to parse: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/temporary_document.go","lineNumber":621,"sourceCode":"\tif len(documentIDs) > 0 {\n\t\tperDocumentBudget = temporaryDocumentPromptBudget / len(documentIDs)\n\t}\n\tseen := make(map[string]struct{}, len(documentIDs))\n\tfor _, documentID := range documentIDs {\n\t\tif _, duplicate := seen[documentID]; duplicate {\n\t\t\tcontinue\n\t\t}\n\t\tseen[documentID] = struct{}{}\n\t\tdocument, err := s.repo.GetScoped(ctx, tenantID, sessionID, documentID)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif document == nil {\n\t\t\treturn nil, fmt.Errorf(\"attachment %s was not found in this session\", documentID)\n\t\t}\n\t\tif document.Status != types.TemporaryDocumentStatusReady {\n\t\t\tif document.Status == types.TemporaryDocumentStatusFailed {\n\t\t\t\treturn nil, fmt.Errorf(\"attachment %s failed to parse: %s\", document.FileName, document.ErrorMessage)\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"attachment %s is still being processed\", document.FileName)\n\t\t}\n\t\tcontent, selected, total := selectTemporaryDocumentContentWithBudget(document, query, perDocumentBudget)\n\t\tresult.Attachments = append(result.Attachments, types.MessageAttachment{\n\t\t\tID: document.ID, URL: document.ResourceRef, FileName: document.FileName,\n\t\t\tFileType: document.FileType, FileSize: document.FileSize, Content: content,\n\t\t\tContentMode: map[bool]string{true: \"full\", false: \"selected_chunks\"}[selected == total],\n\t\t\tTokenCount:  document.TokenCount, SelectedChunks: selected, TotalChunks: total,\n\t\t})\n\t\t// Image-type attachments always expose their image so vision models can\n\t\t// see it directly; text documents only attach extracted images when the\n\t\t// question is visual, to avoid gratuitous multimodal latency.\n\t\tif docparser.IsImageFormat(document.FileType) || isVisualDocumentQuery(query) {\n\t\t\tfor _, image := range temporaryDocumentImageRefs(document.ImageRefs) {\n\t\t\t\tif image.URL != \"\" && len(result.ImageURLs) < 4 {\n\t\t\t\t\tresult.ImageURLs = append(result.ImageURLs, image.URL)\n\t\t\t\t}","sourceCodeStart":603,"sourceCodeEnd":639,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/temporary_document.go#L603-L639","documentation":"The attachment exists and is scoped correctly, but its stored status is TemporaryDocumentStatusFailed — asynchronous parsing failed earlier. The stored ErrorMessage from the failed parse is surfaced to the caller.","triggerScenarios":"ResolveForPrompt encounters a document whose Status == TemporaryDocumentStatusFailed, i.e. a prior Process/parse failed (bad file, unsupported format, ASR error such as error 560-564) and the failure was persisted.","commonSituations":"User attaches a file, parsing fails in the background, and the user immediately sends a message referencing it; duplicate attachments (same file uploaded twice concurrently) can also be marked failed.","solutions":["Surface document.ErrorMessage to the user and re-upload a corrected/valid file","Fix the underlying parse failure (valid format, configure ASR model for audio, supported engine)","Check document status (READY) before sending the message","Retry upload if the failure was transient"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// poll until status resolves before sending message\nif doc.Status != types.TemporaryDocumentStatusReady { waitOrAbort() }","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"failed to parse\") {\n    // show document.ErrorMessage and prompt re-upload\n}","preventionTips":["Check document status before referencing it in a message","Surface persisted ErrorMessage to the end user","Fix the root parse cause (valid format, ASR model configured)"],"tags":["parsing","document","attachment-failed","status"],"backgroundTag":"document-parse-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}