Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASMPET-6723 catch UnicodeDecodeError from os/run_command #54

Merged
merged 12 commits into from
Aug 10, 2023
9 changes: 4 additions & 5 deletions libcsm/sls/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"""

import http
from json import JSONDecodeError
import requests
from libcsm import api
from libcsm.requests.session import get_session
Expand Down Expand Up @@ -69,8 +68,8 @@ def get_xname(self, hostname: str) -> str:
"""
try:
components_response = (self.get_management_components_from_sls()).json()
except JSONDecodeError as error:
raise JSONDecodeError(f'ERROR did not get valid json for management components \
rustydb marked this conversation as resolved.
Show resolved Hide resolved
except ValueError as error:
raise ValueError(f'ERROR did not get valid json for management components \
from sls. {error}') from error

for node in components_response:
Expand All @@ -89,8 +88,8 @@ def get_hostname(self, xname: str) -> str:
"""
try:
components_response = (self.get_management_components_from_sls()).json()
except JSONDecodeError as error:
raise JSONDecodeError(f'ERROR did not get valid json for management components \
except ValueError as error:
raise ValueError(f'ERROR did not get valid json for management components \
from sls. {error}') from error

for node in components_response:
Expand Down
3 changes: 1 addition & 2 deletions libcsm/sls/get_hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"""

import sys
from json import JSONDecodeError
import click
import requests
from libcsm.sls import api
Expand All @@ -46,6 +45,6 @@ def main(xname, api_gateway_address) -> None:
sls_api = api.API(api_gateway_address)
try:
print(sls_api.get_hostname(xname))
except (requests.exceptions.RequestException, KeyError, ValueError, JSONDecodeError) as error:
except (requests.exceptions.RequestException, KeyError, ValueError) as error:
print(f'{error}')
sys.exit(1)
3 changes: 1 addition & 2 deletions libcsm/sls/get_xname.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"""

import sys
from json import JSONDecodeError
import click
import requests
from libcsm.sls import api
Expand All @@ -46,6 +45,6 @@ def main(hostname, api_gateway_address) -> None:
sls_api = api.API(api_gateway_address)
try:
print(sls_api.get_xname(hostname))
except (requests.exceptions.RequestException, KeyError, ValueError, JSONDecodeError) as error:
except (requests.exceptions.RequestException, KeyError, ValueError) as error:
print(f'{error}')
sys.exit(1)