-
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.
Introduce new command error handling system
- Loading branch information
1 parent
658a620
commit 2a0abd6
Showing
22 changed files
with
216 additions
and
96 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
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,2 @@ | ||
from argparse import ArgumentError | ||
from src.exceptions.command_exception import CommandException |
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,10 @@ | ||
class CommandException(Exception): | ||
""" | ||
Custom exception class for handling command-related errors. This exception | ||
allows for the inclusion of specific errors that can't be catched with | ||
ArgumentError and is used in ArgumentParserNoExit. | ||
""" | ||
|
||
def __init__(self, message: str) -> None: | ||
self.message = message | ||
super().__init__(self.message) |
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
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
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 |
---|---|---|
@@ -1,23 +1,30 @@ | ||
import argparse | ||
from typing import Optional | ||
|
||
from src.utils import CommandRequestFields | ||
from src.app_state.app_state import AppState | ||
from src.base_command import BaseCommand | ||
from src.exceptions import ArgumentError, CommandException | ||
|
||
class HighlightRange(BaseCommand): | ||
def __init__(self): | ||
super().__init__( | ||
name="highlight-range", | ||
description="Highlight the nodes whose segments is within the specified range.", | ||
) | ||
|
||
self.parser.add_argument("low", nargs="?", type=int, default=-1) | ||
self.parser.add_argument("high", nargs="?", type=int, default=-1) | ||
|
||
def execute(self, args: list[str], app_state: AppState): | ||
parsed_args: argparse.Namespace = self.parser.parse_args(args) | ||
|
||
command_request_data = app_state.rendering.command_request_data | ||
command_request_data[CommandRequestFields.HIGHLIGHT_RANGE_LOW] = parsed_args.low | ||
command_request_data[CommandRequestFields.HIGHLIGHT_RANGE_HIGH] = parsed_args.high | ||
def execute(self, args: list[str], app_state: AppState) -> Optional[ArgumentError | CommandException]: | ||
try: | ||
parsed_args: argparse.Namespace = self.parser.parse_args(args) | ||
command_request_data = app_state.rendering.command_request_data | ||
command_request_data[CommandRequestFields.HIGHLIGHT_RANGE_LOW] = parsed_args.low | ||
command_request_data[CommandRequestFields.HIGHLIGHT_RANGE_HIGH] = parsed_args.high | ||
except ArgumentError as e: | ||
return e | ||
except CommandException as e: | ||
return e | ||
|
||
highlight_range_cmd = HighlightRange() |
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
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
Oops, something went wrong.