autograder.error

 1import sys
 2import typing
 3
 4_exit_on_error_for_testing: bool = True  # pylint: disable=invalid-name
 5"""
 6Control if exit_from_error() should actually exit.
 7Testing infrastructure can set this to control exit behavior.
 8"""
 9
10def exit_from_error(exit_status: int = 1) -> None:
11    """
12    Exit because an error occurred.
13    Testing infrastructure can set _exit_on_error_for_testing to false to avoid exiting.
14    """
15
16    if (not _exit_on_error_for_testing):
17        return
18
19    sys.exit(exit_status)
20
21class AutograderError(Exception):
22    """ General errors from the autograder (including this interface). """
23
24class APIError(AutograderError):
25    """ Errors that specifically come from the autograder server. """
26
27    def __init__(self, code: typing.Union[int, None], message: str) -> None:
28        super().__init__(message)
29
30        self.code: typing.Union[int, None] = code
31        """ The HTTP status code. """
32
33class ConnectionError(AutograderError):
34    """ An error stemming from a bad network connection. """
def exit_from_error(exit_status: int = 1) -> None:
11def exit_from_error(exit_status: int = 1) -> None:
12    """
13    Exit because an error occurred.
14    Testing infrastructure can set _exit_on_error_for_testing to false to avoid exiting.
15    """
16
17    if (not _exit_on_error_for_testing):
18        return
19
20    sys.exit(exit_status)

Exit because an error occurred. Testing infrastructure can set _exit_on_error_for_testing to false to avoid exiting.

class AutograderError(builtins.Exception):
22class AutograderError(Exception):
23    """ General errors from the autograder (including this interface). """

General errors from the autograder (including this interface).

class APIError(AutograderError):
25class APIError(AutograderError):
26    """ Errors that specifically come from the autograder server. """
27
28    def __init__(self, code: typing.Union[int, None], message: str) -> None:
29        super().__init__(message)
30
31        self.code: typing.Union[int, None] = code
32        """ The HTTP status code. """

Errors that specifically come from the autograder server.

APIError(code: Optional[int], message: str)
28    def __init__(self, code: typing.Union[int, None], message: str) -> None:
29        super().__init__(message)
30
31        self.code: typing.Union[int, None] = code
32        """ The HTTP status code. """
code: Optional[int]

The HTTP status code.

class ConnectionError(AutograderError):
34class ConnectionError(AutograderError):
35    """ An error stemming from a bad network connection. """

An error stemming from a bad network connection.