-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle resource alias not found error (#29)
* Handle resource alias not found error * Move read alias file to utils
- Loading branch information
Showing
5 changed files
with
67 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
from rich.console import Console | ||
|
||
CONSOLE = Console() | ||
|
||
ALIASES_FILE_PATH = "app/manifests/aliases.json" | ||
|
||
HOW_TO_UPDATE_ALIASES_MESSAGE = ( | ||
"How to update the resource aliases file: " | ||
"https://github.com/RedHatQE/must-gather-explorer?tab=readme-ov-file#update-cluster-resources-aliases\n" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class MissingResourceKindAliasError(Exception): | ||
def __init__(self, requested_kind: str) -> None: | ||
self.requested_kind = requested_kind | ||
|
||
def __repr__(self) -> str: | ||
return f"Resource kind alias '{self.requested_kind}' not found" | ||
|
||
|
||
class FailToReadJSONFileError(Exception): | ||
def __init__(self, file_name: str) -> None: | ||
self.file_name = file_name | ||
|
||
def __repr__(self) -> str: | ||
return f"Can't read file '{self.file_name}'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import json | ||
|
||
from app.constants import ALIASES_FILE_PATH, HOW_TO_UPDATE_ALIASES_MESSAGE, CONSOLE | ||
from app.exceptions import FailToReadJSONFileError | ||
|
||
|
||
def read_aliases_file(raise_on_error: bool = True) -> dict[str, list[str]]: | ||
try: | ||
with open(ALIASES_FILE_PATH) as aliases_file: | ||
return json.load(aliases_file) | ||
except (FileNotFoundError, json.JSONDecodeError) as exp: | ||
if raise_on_error: | ||
CONSOLE.print( | ||
f"[bold red]Error:[/bold red] Can't read the aliases_file\n" | ||
f"Error details: {exp}\n" | ||
f"{HOW_TO_UPDATE_ALIASES_MESSAGE}" | ||
) | ||
raise FailToReadJSONFileError(file_name=ALIASES_FILE_PATH) | ||
return {} |