Skip to content

Commit

Permalink
fix(gateway): catch JSONDecodeError Requests<2.27
Browse files Browse the repository at this point in the history
Catch JSONDecodeError from simpleson external library and json
standard library module, with the logic required with Requests < 2.27.
  • Loading branch information
rezib committed Nov 13, 2024
1 parent efb0a60 commit 90b0f0e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix compatibility issue with Requests >= 2.32.2 (#350).
- Return HTTP/404 not found with meaningful error message when requesting
unexisting node.
- gateway: catch generic `requests.exceptions.RequestException` when retrieving
information from agents to avoid `AttributeError` with more specific
exceptions on old versions on _Requests_ library (#391).
- gateway:
- Catch generic `requests.exceptions.RequestException` when retrieving
information from agents to avoid `AttributeError` with more specific
exceptions on old versions on _Requests_ library (#391).
- Catch `JSONDecodeError` from _simpleson_ external library and _json_
standard library module not managed by Requests < 2.27.
- frontend: Update dependencies to fix CVE-2024-45812 and CVE-2024-45811 (vite),
CVE-2024-47068 (rollup).

Expand Down
7 changes: 6 additions & 1 deletion slurmweb/apps/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
from . import SlurmwebWebApp
from ..views import SlurmwebAppRoute
from ..views import gateway as views
from ..errors import SlurmwebConfigurationError, SlurmwebAgentError
from ..errors import (
SlurmwebConfigurationError,
SlurmwebCompatJSONDecodeError,
SlurmwebAgentError,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -86,6 +90,7 @@ def agents(self):
agent = self._agent_info(url.geturl())
except (
requests.exceptions.RequestException,
SlurmwebCompatJSONDecodeError,
SlurmwebAgentError,
) as err:
logger.error(
Expand Down
16 changes: 16 additions & 0 deletions slurmweb/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,19 @@ class SlurmwebCacheError(Exception):

class SlurmwebMetricsDBError(Exception):
pass


# Alias JSONDecodeError from simplejson external library and json standard library
# module to catch generically the error raised with Requests < 2.27 on old systems in
# presence of unexepected non-JSON responses.
#
# This is not needed with Requests >= 2.27 where the same logic is implemented with
# requests.exceptions.JSONDecodeError wildcard exception. For reference, see:
# https://github.com/psf/requests/pull/5856

try:
from simplejson import JSONDecodeError
except ImportError:
from json import JSONDecodeError

SlurmwebCompatJSONDecodeError = JSONDecodeError

0 comments on commit 90b0f0e

Please sign in to comment.