Propagate errors instead of swallowing them across pipeline and scripts - #3
Open
devin-ai-integration[bot] wants to merge 3 commits into
Open
Propagate errors instead of swallowing them across pipeline and scripts#3devin-ai-integration[bot] wants to merge 3 commits into
devin-ai-integration[bot] wants to merge 3 commits into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Exios66
approved these changes
Jul 29, 2026
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…val script Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Audit of error handling in
src/andscripts/. Failures were being hidden in three ways: swallowed exceptions (except: pass, fallbacks to empty values), errors logged but never surfaced to the caller/exit code, and API responses whose failures were treated as "no prediction". Every script now returns a non-zero exit code when inputs are missing or any item fails, and library code raises typed exceptions.Highlights:
src/openrouter_classifier.py— a malformed/error API response used to become an empty prediction that scored as a wrong answer:New
OpenRouterErroralso covers connection failures, non-JSON bodies, HTTP errors (previouslyprint+ reraise of a bareHTTPErrorwith no context), and unreadable image files.clean_predictionnow warns when the model output contains no valid class name instead of silently returning arbitrary text.src/document_processor.py— the Tesseract configuration was wrapped intry: ... except Exception: pass, which never actually caught anything (attribute assignment can't fail) and left a Windows-only path configured on other platforms:Also: new
DocumentProcessingErrorfor unreadable images, OCR failures (TesseractNotFoundError/TesseractErrornow get an actionable message instead of a raw pytesseract error), and failed image/JSON writes;logger.error(e)→logger.exceptionso tracebacks are kept; batch results carryerror_type;_optimize_imageguards against zero/non-numeric DPI metadata (previouslyZeroDivisionError); the__main__block returns an exit code instead of printingError: ...and exiting 0.src/env_utils.py— split the shared helper so library code can propagate instead of exiting mid-call, and the optional-dotenvexcept ImportError: passnow says why env vars may be missing:scripts/—run_tiff_processing.py,create_balanced_dataset.py,eda_analysis.py,eda_dimensions_summary.py,create_fixed_size_dataset.py,braintrust_metrics_visual.py,braintrust_openrouter_input.py,estimate_openrouter_cost.py,download_dataset.pyall validate inputs up front andsys.exit(main()). Notable per-file fixes:eda_dimensions_summary.py: unreadable images were counted intoskippedwith no reason recorded — errors are now printed and listed in the summary JSON.eda_analysis.py: an empty dataset previously producedAttributeError/KeyErrordeep in analysis; now raises a clear error, and unreadable files are reported in the JSON report.create_balanced_dataset.py: a single failingshutil.copy2aborted the run mid-way; failures are per-file, logged, andMISMATCH/MISSINGverification results now fail the run.braintrust_metrics_visual.py:sys.exit()inside the fetch helper replaced byBraintrustFetchError; retry loop no longer relies on a possibly stalerespand now retries allRequestExceptions (not justTimeout); an experiment with zero usable rows errors out instead of rendering an empty chart; the deadif metrics.get("tokens"): passbranch now populatesreasoning_tokens_avg(it was always reported as 0), and the hardcoded| Errors | 0 |row in the generated experiment log reports the real error count.braintrust_openrouter_input.py: a missing/misnamed dataset dir silently ran an eval over 0 images; now raises, and skipped unlabeled filenames are reported.Verified by unit-poking the new failure paths (fake non-JSON / error-body / empty-
choicesresponses, missing image files, missing Tesseract, missing input dirs, missing env vars) and confirming the scripts exit 1. Ruff:blind-except11 → 1 (the remaining one intentionally wrapskagglehub),try-except-passandunused-variablegone; remaining findings are pre-existing style issues. Mergedmain(#2's sharedsrc/utilities) into the branch — the error handling is reconciled withfind_images/encode_image_base64/print_header/require_env.Link to Devin session: https://app.devin.ai/sessions/a40dcf36c84c4e6bb637d7826d6fcb2c
Requested by: @Exios66