Skip to content

Handle non-JSON error payloads gracefully#172

Merged
euanh merged 1 commit intoapple:mainfrom
William-Laverty:fix-non-json-error-handling
Feb 2, 2026
Merged

Handle non-JSON error payloads gracefully#172
euanh merged 1 commit intoapple:mainfrom
William-Laverty:fix-non-json-error-handling

Conversation

@William-Laverty
Copy link
Contributor

Summary

Fixes #136

When a registry returns an error response with a non-JSON body (e.g., plain text like "page not found" from registry:2), ContainerRegistry now handles this gracefully instead of propagating a confusing JSONDecoder error.

Changes

  1. Added new error case RegistryClientError.unexpectedRegistryResponse(status:body:)
  2. Modified both executeRequestThrowing methods to catch DecodingError when parsing error responses
  3. When JSON decoding fails, throws the new error with the HTTP status code and raw response body

Before

Error: dataCorrupted at coding path [] (The given data was not valid JSON.)

After

Registry returned HTTP 404: page not found

Testing

The fix handles the case mentioned in #136 where opening an upload session with an invalid repository name causes registry:2 to respond with a 404 and plain text body "page not found".

Fixes #136

When a registry returns an error response with a non-JSON body (e.g.,
plain text like 'page not found'), ContainerRegistry now catches the
DecodingError and throws a more informative RegistryClientError with
the HTTP status code and raw response body, instead of propagating
the confusing JSONDecoder error.

Added new error case:
- RegistryClientError.unexpectedRegistryResponse(status:body:)

This provides clearer error messages when registries don't follow
the OCI distribution spec for error responses.
@euanh euanh self-requested a review February 2, 2026 09:21
@euanh euanh added the semver/patch No public API change. label Feb 2, 2026
@euanh euanh merged commit d9a516a into apple:main Feb 2, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ContainerRegistry should handle non-JSON error payloads more gracefully

2 participants