{"record":{"id":"c3184648b7919123","repo":"Tencent/WeKnora","slug":"open-source-file-w","errorCode":null,"errorMessage":"open source file: %w","messagePattern":"open source file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/temporary_document.go","lineNumber":353,"sourceCode":"\tchunks := make([]types.TemporaryDocumentChunk, 0, len(parts))\n\tfor _, part := range parts {\n\t\tchunks = append(chunks, types.TemporaryDocumentChunk{\n\t\t\tSeq: part.Seq, Content: part.Content, ContextHeader: part.ContextHeader,\n\t\t\tStart: part.Start, End: part.End, TokenCount: chunker.ApproxTokenCount(part.EmbeddingContent(), lang),\n\t\t})\n\t}\n\tchunksJSON, _ := json.Marshal(chunks)\n\timagesJSON, _ := json.Marshal(images)\n\tmetadataJSON, _ := json.Marshal(metadata)\n\treturn s.repo.MarkReady(ctx, payload.TenantID, payload.DocumentID, content,\n\t\ttypes.JSON(chunksJSON), types.JSON(imagesJSON), types.JSON(metadataJSON),\n\t\tchunker.ApproxTokenCount(content, lang), len(chunks), time.Now())\n}\n\nfunc (s *temporaryDocumentService) parse(ctx context.Context, document *types.TemporaryDocument) (string, []types.TemporaryDocumentImage, map[string]string, error) {\n\tfile, err := s.fileService.GetFile(ctx, document.ResourceRef)\n\tif err != nil {\n\t\treturn \"\", nil, nil, fmt.Errorf(\"open source file: %w\", err)\n\t}\n\tdefer file.Close()\n\tdata, err := io.ReadAll(io.LimitReader(file, secutils.GetMaxFileSizeMB()*1024*1024+1))\n\tif err != nil {\n\t\treturn \"\", nil, nil, fmt.Errorf(\"read source file: %w\", err)\n\t}\n\text := document.FileType\n\tvar options types.TemporaryDocumentCreateOptions\n\t_ = json.Unmarshal(document.ProcessingOptions, &options)\n\tif options.ParserEngine == \"\" || options.ParserEngine == \"auto\" {\n\t\tif tenant, ok := ctx.Value(types.TenantInfoContextKey).(*types.Tenant); ok && tenant != nil {\n\t\t\toptions.ParserEngine = tenant.ParserEngineConfig.ResolveChatParserEngine(ext)\n\t\t}\n\t}\n\tif _, ok := temporaryTextExtensions[ext]; ok && (options.ParserEngine == \"\" || options.ParserEngine == \"auto\") {\n\t\treturn string(data), nil, map[string]string{\"parser\": \"plain_text\"}, nil\n\t}\n\tif docparser.IsAudioFormat(ext) {","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/temporary_document.go#L335-L371","documentation":"The parse step (run by Process via the async task) fetches the stored file through fileService.GetFile using document.ResourceRef; any failure there is wrapped as 'open source file'. Root causes live in the file service/storage layer: missing object, bad credentials, or storage backend errors.","triggerScenarios":"ResourceRef points to a deleted or never-uploaded object; storage credentials invalid/expired; storage backend (S3/GCS/local FS) unreachable; path format changes after migration.","commonSituations":"Lifecycle rules deleting objects before parsing runs; expired presigned credentials; local dev paths that don't exist in prod; storage region misconfiguration.","solutions":["Check document.ResourceRef exists in the storage backend and the file service can read it","Verify storage credentials/config for the environment the worker runs in","Inspect the wrapped cause (%w chain) to distinguish not-found vs permission vs network","Re-trigger the parse after fixing storage; or re-upload the source file if the object is gone"],"exampleFix":"// before\nfile, err := s.fileService.GetFile(ctx, document.ResourceRef)\nif err != nil {\n    return \"\", nil, nil, fmt.Errorf(\"open source file: %w\", err)\n}\n// after\nfile, err := s.fileService.GetFile(ctx, document.ResourceRef)\nif err != nil {\n    logger.Error(\"parse: cannot open source\", \"ref\", document.ResourceRef, \"doc\", document.ID, \"err\", err)\n    return \"\", nil, nil, fmt.Errorf(\"open source file: %w\", err)\n}","handlingStrategy":"retry","validationCode":"// Pre-check the object exists before enqueuing parse:\nif _, err := fileService.Stat(ctx, doc.ResourceRef); err != nil { return fmt.Errorf(\"source missing: %w\", err) }","typeGuard":null,"tryCatchPattern":"err := svc.Process(ctx, task)\nif err != nil && strings.HasPrefix(err.Error(), \"open source file:\") {\n    if errors.Is(err, os.ErrNotExist) { markPermanentFailure(doc) } else { return err } // asynq retries transient\n}","preventionTips":["Ensure storage lifecycle rules outlive parse windows","Validate ResourceRef at Create time","Give workers correct storage credentials/config","Distinguish permanent (missing object) vs transient (network) failures before retrying"],"tags":["file-storage","parsing","async-worker"],"backgroundTag":"source-file-open-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}