{"record":{"id":"50c9e1555bbac4d0","repo":"Tencent/WeKnora","slug":"anydoc-scanned-pdf-fallback-returned-no-result-for","errorCode":null,"errorMessage":"anydoc scanned-PDF fallback returned no result for %q","messagePattern":"anydoc scanned-PDF fallback returned no result for %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/docparser/anydoc_reader.go","lineNumber":100,"sourceCode":"}\n\nfunc (r *AnydocReader) readScannedPDF(ctx context.Context, req *types.ReadRequest, convertErr error) (*types.ReadResult, error) {\n\tif !r.canFallback() {\n\t\tif convertErr != nil {\n\t\t\treturn nil, fmt.Errorf(\"anydoc conversion failed for %q: %w\", req.FileName, convertErr)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"anydoc conversion failed for %q: PDF has no extractable text; OCR is required\", req.FileName)\n\t}\n\n\tlogger.Infof(ctx, \"[anydoc] %q has no text layer, falling back to builtin for scanned-PDF OCR\", req.FileName)\n\tfallbackReq := *req\n\tfallbackReq.ParserEngine = BuiltinEngineName\n\tresult, err := r.fallback.Read(ctx, &fallbackReq)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"anydoc scanned-PDF fallback failed for %q: %w\", req.FileName, err)\n\t}\n\tif result == nil {\n\t\treturn nil, fmt.Errorf(\"anydoc scanned-PDF fallback returned no result for %q\", req.FileName)\n\t}\n\tif result.Metadata == nil {\n\t\tresult.Metadata = map[string]string{}\n\t}\n\tif result.Metadata[\"parser\"] == \"\" {\n\t\tresult.Metadata[\"parser\"] = BuiltinEngineName\n\t}\n\tresult.Metadata[\"anydoc_fallback\"] = \"scanned_pdf\"\n\tif result.Metadata[\"image_source_type\"] == \"\" {\n\t\tresult.Metadata[\"image_source_type\"] = \"scanned_pdf\"\n\t}\n\treturn result, nil\n}\n\nfunc (r *AnydocReader) canFallback() bool {\n\tif r.fallback == nil {\n\t\treturn false\n\t}","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/docparser/anydoc_reader.go#L82-L118","documentation":"In the anydoc document reader, when the primary parser detects a scanned PDF it re-reads the file with a fallback (built-in OCR) engine. This error is returned when that fallback reports success but yields a nil result, i.e. no readable content could be produced for the scanned PDF.","triggerScenarios":"Calling Read on a scanned (image-only) PDF where the primary engine flags it as scanned and r.fallback.Read returns (nil, nil) — a nil-result-without-error condition in the fallback reader.","commonSituations":"Blank or corrupted scanned PDFs; OCR engine installed but producing empty output; misconfigured fallback reader in the registry; PDFs whose pages are pure images with no extractable text even after OCR.","solutions":["Open the PDF and confirm it actually contains scannable content; a blank/corrupt file must be fixed at the source.","Verify the fallback (built-in OCR) engine is correctly configured and healthy for this tenant.","Inspect result construction in the fallback reader — a nil result with nil error is a bug; log req.FileName and the primary engine's scan detection metadata.","Handle the error upstream by informing the user the scanned PDF could not be converted."],"exampleFix":"// before\nresult, err := r.fallback.Read(ctx, &fallbackReq)\nif err != nil { return nil, ... }\n// after\nresult, err := r.fallback.Read(ctx, &fallbackReq)\nif err != nil || result == nil {\n    return nil, fmt.Errorf(\"scanned-PDF fallback produced no content for %q\", req.FileName)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"res, err := reader.Read(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"scanned-PDF fallback\") {\n    // notify user the scanned PDF could not be converted; inspect fallback engine config\n}","preventionTips":["Validate PDFs are readable (non-blank) before ingestion.","Keep the OCR fallback engine configured and healthy.","Treat nil-result-without-error from any reader as a bug and assert on it.","Surface parser metadata (result.Metadata[\"parser\"]) when debugging scans."],"tags":["pdf","ocr","docparser","nil-result"],"backgroundTag":"scanned-pdf-parse-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}