Skip to content

fix: raise an informative error for a non-JSON manifest response - #268

Merged
vsoch merged 1 commit into
oras-project:mainfrom
Rohilalala:fix/manifest-non-json-error
Nov 18, 2026
Merged

vsoch merged 1 commit into
oras-project:mainfrom
Rohilalala:fix/manifest-non-json-error

Conversation

@Rohilalala

Copy link
Copy Markdown
Contributor

What

get_manifest() called response.json() immediately after the status check, so a 200 carrying a non-JSON body (a reverse-proxy error page, an empty body, truncated content) surfaced as a bare JSONDecodeError with no URL, status, or body — the "non-informative JSONDecodeError" in #223.

Before / after

Before:

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

After:

ValueError: Could not parse the manifest from http://registry/v2/repo/manifests/tag as JSON (status 200, Content-Type text/html). Response body starts with: '<html><body>502 Bad Gateway</body></html>'

The decode failure is caught as ValueError — the common base of the requests, simplejson and stdlib json JSONDecodeError variants — so it also behaves on requests < 2.27, where requests.exceptions.JSONDecodeError does not exist.

Tests

oras/tests/test_provider.py::test_get_manifest_non_json_response, parametrised over both the requests and the stdlib decode error. No live registry needed:

pytest oras/tests/test_provider.py::test_get_manifest_non_json_response

Not fixed here

get_tags() and a couple of other response.json() call sites can raise the same bare error on a non-JSON body; left out to keep this scoped to the path #223 reports.

Closes #223.

get_manifest() called response.json() straight after the status check, so a
200 carrying a non-JSON body (a proxy error page, an empty body) surfaced as a
bare JSONDecodeError with no URL, status, or body context (oras-project#223).

Catch the decode failure (ValueError, the common base of the requests,
simplejson and stdlib json JSONDecodeError variants) and re-raise a ValueError
that names the request, the status code, the Content-Type, and a snippet of
what came back instead.

Signed-off-by: Aditya <205600203+Rohilalala@users.noreply.github.com>
@Rohilalala
Rohilalala requested a review from vsoch as a code owner November 17, 2026 11:36

@vsoch vsoch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Straight forward and logical. We're good to merge.

@vsoch
vsoch merged commit f9640c3 into oras-project:main Nov 18, 2026
5 checks passed
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.

Can kaboom with non-informative JSONDecodeError

2 participants