Skip to content

Commit

Permalink
fix: handle JSONDecodeError in fatbuildrctl
Browse files Browse the repository at this point in the history
Properly handle and report JSON decode error in fatbuildrctl in case of
unexpected failure in fatbuildrweb.

fix #146
  • Loading branch information
rezib committed Jul 11, 2024
1 parent fe8e1b4 commit ec74b33
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
syntax error during RPM packages builds (#170).
- Fix crash of `fatbuildrctl` on missing source definition in YAML artifact
definition file (#171).
- Handle JSON decode error in `fatbuildrctl` in case of unexpected failure in
`fatbuildrweb` (#146).
- docs:
- Add missing path parameter in REST API to retrieve artifact information.
- Add missing optional `architectures` parameter in instances pipelines
Expand Down
13 changes: 13 additions & 0 deletions fatbuildr/protocols/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@

import requests

# External requests library can use simplejson when available, with fallback to
# standard json library. This module may receive JSONDecodeError from this
# package, or from the standard library. Adopt the same import logic to catch
# the correct error.
try:
from simplejson import JSONDecodeError
except ImportError:
from json import JSONDecodeError

from . import JsonInstance, JsonRunnableTask, JsonArtifact
from ..client import AbstractClient
from ...errors import FatbuildrServerError, FatbuildrServerPermissionError
Expand All @@ -40,6 +49,10 @@ def error_handler_wrapper(*args, **kwargs):
raise FatbuildrServerError(
f"unable to connect to {args[0].uri}: {err}"
)
except JSONDecodeError as err:
raise FatbuildrServerError(
f"unable to decode JSON response to {args[0].uri}: {err}"
)

return error_handler_wrapper

Expand Down

0 comments on commit ec74b33

Please sign in to comment.