Skip to content

fix: LabelMeReader raises on unreadable input instead of returning None - #208

Merged
petercorke merged 4 commits into
mainfrom
fix/labelme-reader-raises
Nov 22, 2026
Merged

petercorke merged 4 commits into
mainfrom
fix/labelme-reader-raises

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

LabelMeReader.__init__ wrapped the file and URL read in a broad try/except that swallowed OSError, json.JSONDecodeError, TypeError and ValueError and returned None, leaving a half-initialised reader that failed later with a confusing error. The try/except is removed so the original exception propagates.

The fix is by @zw1915 from PR 156 (LabelMeReader raises, open), which this supersedes. It is carried here with their authorship credit (Co-Authored-By trailer) plus two additions the review asked for:

  • tests that a missing file raises FileNotFoundError and invalid JSON raises json.JSONDecodeError (both fail on main);
  • a :raises: entry and a .. versionchanged:: 2.5.0 note in the docstring.

Refs #150 (Sources.py quick wins), which tracks several items and stays open.

Testing

pytest tests/test_image_sources.py -k LabelMe: 2 passed, 1 skipped (the existing reader test needs labelme). The two new tests fail on main without the fix. mypy reports no issues. Not run: the full suite locally, or the URL path.

This change was written with AI assistance (Claude Code) and the diff has been read by the maintainer.

🤖 Generated with Claude Code

Remove the broad try/except in LabelMeReader.__init__, which swallowed
OSError and JSON errors and returned a half-initialised reader. The
original exception now propagates. Adds tests for a missing file and for
invalid JSON.

Refs #150

Co-Authored-By: zw1915 <134981642+zw1915@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit 81daa6a into main Nov 22, 2026
34 checks passed
@petercorke
petercorke deleted the fix/labelme-reader-raises branch November 22, 2026 02:30
@github-actions github-actions Bot mentioned this pull request Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant