Skip to content

api

error.api

ERROR_CODE_BOOK module-attribute

ERROR_CODE_BOOK: Dict[str, Type[SaigeError]] = {}

SUCCESS module-attribute

SUCCESS = 0

SUCCESS_MESSAGE module-attribute

SUCCESS_MESSAGE = 'Success'

MIN_ERROR_CODE module-attribute

MIN_ERROR_CODE = -999999

MAX_ERROR_CODE module-attribute

MAX_ERROR_CODE = -300000

ERROR_CODE_UNDEFINED module-attribute

ERROR_CODE_UNDEFINED: str = '999'

ERROR_MESSAGE_UNDEFINED module-attribute

ERROR_MESSAGE_UNDEFINED: str = 'Unknown error'

error_handler module-attribute

SaigeToolkitError

SaigeToolkitError(message=None)

Bases: SaigeError

https://dev.azure.com/SaigeResearch/Research/_git/SaigeToolkit

Torch dataloader에서 작업 중 exception 발생 시 torch가 message를 넣어서 reraise하는 경우가 있음. 참고: https://teams.microsoft.com/l/message/19:874deea9bde44c2f9c2c43d4bc002a58@thread.tacv2/1688547469317?tenantId=4098be5f-d82a-474c-b4b6-a95727b671eb&groupId=3f51c33d-7ce9-4b2c-bf75-6d1032c4183b&parentMessageId=1688547469317&teamName=%EC%97%B0%EA%B5%AC%ED%8C%80&channelName=%5BPR%5D%20SaigeToolkit&createdTime=1688547469317&allowXTenantAccess=false

Source code in SaigeToolkit/error/base.py
def __init__(self, message=None) -> None:
    """
    Torch dataloader에서 작업 중 exception 발생 시 torch가 message를 넣어서 reraise하는 경우가 있음.
    참고: https://teams.microsoft.com/l/message/19:874deea9bde44c2f9c2c43d4bc002a58@thread.tacv2/1688547469317?tenantId=4098be5f-d82a-474c-b4b6-a95727b671eb&groupId=3f51c33d-7ce9-4b2c-bf75-6d1032c4183b&parentMessageId=1688547469317&teamName=%EC%97%B0%EA%B5%AC%ED%8C%80&channelName=%5BPR%5D%20SaigeToolkit&createdTime=1688547469317&allowXTenantAccess=false
    """
    pass

UndefinedErrorCodeError

UndefinedErrorCodeError(message=None)

Bases: SaigeToolkitError

Torch dataloader에서 작업 중 exception 발생 시 torch가 message를 넣어서 reraise하는 경우가 있음. 참고: https://teams.microsoft.com/l/message/19:874deea9bde44c2f9c2c43d4bc002a58@thread.tacv2/1688547469317?tenantId=4098be5f-d82a-474c-b4b6-a95727b671eb&groupId=3f51c33d-7ce9-4b2c-bf75-6d1032c4183b&parentMessageId=1688547469317&teamName=%EC%97%B0%EA%B5%AC%ED%8C%80&channelName=%5BPR%5D%20SaigeToolkit&createdTime=1688547469317&allowXTenantAccess=false

Source code in SaigeToolkit/error/base.py
def __init__(self, message=None) -> None:
    """
    Torch dataloader에서 작업 중 exception 발생 시 torch가 message를 넣어서 reraise하는 경우가 있음.
    참고: https://teams.microsoft.com/l/message/19:874deea9bde44c2f9c2c43d4bc002a58@thread.tacv2/1688547469317?tenantId=4098be5f-d82a-474c-b4b6-a95727b671eb&groupId=3f51c33d-7ce9-4b2c-bf75-6d1032c4183b&parentMessageId=1688547469317&teamName=%EC%97%B0%EA%B5%AC%ED%8C%80&channelName=%5BPR%5D%20SaigeToolkit&createdTime=1688547469317&allowXTenantAccess=false
    """
    pass

get_error_handler

get_error_handler(head_error: Type[SaigeError])

Returns error handling decorator The handler wraps the original return value into (error_code, return_value) tuple.

Parameters:

Source code in SaigeToolkit/error/handler.py
def get_error_handler(head_error: Type[SaigeError]):
    """Returns error handling decorator
    The handler wraps the original return value into (error_code, return_value) tuple.

    Args:
        head_error (Type[SaigeError]): head error
    """

    def error_handler(function: Callable[P, T]) -> Callable[P, Tuple[int, Optional[T]]]:
        @wraps(function)
        def decorator(*args: P.args, **kwargs: P.kwargs) -> Tuple[int, Optional[T]]:
            try:
                return (SUCCESS, function(*args, **kwargs))

            except SaigeError as e:
                error_code = -int(head_error.head + e.repo + e.code)
                return (error_code, None)

            except Exception as e:
                error = KNOWN_ERRORS.get(f"{e.__class__.__module__}.{e.__class__.__qualname__}")

                if error is None:
                    print(traceback.format_exc(), file=sys.stderr)
                    repo, code = head_error.repo, ERROR_CODE_UNDEFINED
                else:
                    repo, code = error.repo, error.code

                error_code = -int(head_error.head + repo + code)
                return (error_code, None)

        return decorator

    return error_handler

get_error_message

get_error_message(error_code: int) -> str

입력으로 받은 error_code에 해당하는 error_message를 반환합니다.

Parameters:

  • error_code (int) –

    error_code

Raises:

Returns:

  • str ( str ) –

    error_message

Source code in SaigeToolkit/error/api.py
@error_handler
def get_error_message(error_code: int) -> str:
    """입력으로 받은 error_code에 해당하는 error_message를 반환합니다.

    Args:
        error_code (int): error_code

    Raises:
        UndefinedErrorCodeError: 정의되지 않은 error_code를 입력으로 받을 경우 발생하는 error

    Returns:
        str: error_message
    """

    if error_code == SUCCESS:
        return SUCCESS_MESSAGE
    elif not MIN_ERROR_CODE <= int(error_code) <= MAX_ERROR_CODE:
        raise UndefinedErrorCodeError

    code_digits = str(-error_code).zfill(6)
    repo = code_digits[1:3]
    code = code_digits[3:]
    code_book_key = repo + code

    if code == ERROR_CODE_UNDEFINED:
        error_message = ERROR_MESSAGE_UNDEFINED
    elif code_book_key not in ERROR_CODE_BOOK:
        raise UndefinedErrorCodeError
    else:
        error_message = ERROR_CODE_BOOK[code_book_key].message

    return error_message