Abstract duplicate code in performing OCR - #16617
Conversation
PR Summary by QodoCentralize OCR process execution and deduplicate engine logic
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo
1.
|
| /// @param pdfPath the file to perform OCR on. | ||
| /// @return the result of the OCR operation with the extracted text or an error message. | ||
| OcrResult performOcrAndEmbedText(Path pdfPath); | ||
| OcrResult performOcrAndEmbedText(Path pdfPath) throws IOException; |
There was a problem hiding this comment.
2. Exception bypasses ocr result 🐞 Bug ≡ Correctness
OcrEngine.performOcrAndEmbedText now declares throws IOException even though failures are modeled as OcrResult, and DoclingEngine lets embedText IOExceptions propagate. In the GUI this routes to BackgroundTask.onFailure (generic message) instead of the localized OcrResult.Failure path.
Agent Prompt
### Issue description
The OCR API now mixes two error channels: `OcrResult.Failure` and checked `IOException`. `DoclingEngine` can throw from `embedText(...)`, which is then handled by the GUI as an “unexpected error” instead of a localizable OCR failure reason.
### Issue Context
`OcrResult` is explicitly designed to carry a localizable `OcrFailureReason`. Keeping OCR failures inside `OcrResult` ensures the GUI can consistently display user-friendly messages.
### Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/ocr/OcrEngine.java[11-20]
- jablib/src/main/java/org/jabref/logic/ocr/docling/DoclingEngine.java[50-75]
- jabgui/src/main/java/org/jabref/gui/linkedfile/OcrLinkedFileAction.java[88-110]
- jablib/src/main/java/org/jabref/logic/ocr/OcrResult.java[5-39]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| public static OcrResult performOcr(ArrayList<String> command, String engineName) { | ||
| Process process = null; | ||
| try { | ||
| ProcessBuilder processBuilder = new ProcessBuilder(command); |
There was a problem hiding this comment.
If this is too complex, you can play around with https://github.com/itsallcode/simple-process
Summary
Abstract duplicate code for performing OCR to Ocrutils
AI usage
NA
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)