Source code for pyx12.error_item

######################################################################
# Copyright
#   John Holland <john@zoner.org>
# All rights reserved.
#
# This software is licensed as described in the file LICENSE.txt, which
# you should have received as part of this distribution.
#
######################################################################

""" """

from __future__ import annotations

from dataclasses import dataclass
from typing import Any

from .error_codes import ERROR_CODES
from .errors import EngineError

[docs] isa_errors = ( "000", "001", "002", "003", "004", "005", "006", "007", "008", "009", "010", "011", "012", "013", "014", "015", "016", "017", "018", "019", "020", "021", "022", "023", "024", "025", "026", "027", "028", "029", "030", "031", )
@dataclass(slots=True, frozen=True)
[docs] class ErrorItem:
[docs] err_cde: str
[docs] err_str: str
@dataclass(slots=True, frozen=True)
[docs] class ISAError(ErrorItem): def __post_init__(self) -> None: if self.err_cde not in isa_errors: raise EngineError('Invalid ISA level error code "%s"' % (self.err_cde))
@dataclass(slots=True, frozen=True)
[docs] class SegError(ErrorItem):
[docs] err_val: str | None = None
[docs] src_line: int | None = None
# Walker-supplied context for errh.add_seg(map_node, seg_data, seg_count, # cur_line=src_line, ls_id) before the err_handler tree attaches the # error. None means the wrapper should leave the cursor where it was # (used for "usage='N'" emissions that historically attach to the prior # segment cursor).
[docs] map_node: Any = None
[docs] seg_data: Any = None
[docs] seg_count: int | None = None
[docs] ls_id: str | None = None
def __post_init__(self) -> None: # PR 5: producers all emit pyx12 codes from ERROR_CODES. The # legacy raw-X12 fallback that accepted "1"-"8" is gone; an # unknown err_cde here is now a hard error. if self.err_cde not in ERROR_CODES: raise EngineError( 'Unknown pyx12 error code "%s" (not in pyx12.error_codes.ERROR_CODES)' % (self.err_cde) )
@dataclass(slots=True, frozen=True)
[docs] class EleError(ErrorItem):
[docs] err_val: str | None = None
[docs] refdes: str | None = None
# map_node carries the element node ref for cursor materialization in the # err_handler tree. None means the wrapper should leave the cursor where # it was (used for composite-/seg-level errors that historically attach # to the prior cursor).
[docs] map_node: Any = None
def __post_init__(self) -> None: # PR 5: producers all emit pyx12 codes from ERROR_CODES. The # legacy raw-X12 fallback that accepted "1"-"10" is gone; an # unknown err_cde here is now a hard error. if self.err_cde not in ERROR_CODES: raise EngineError( 'Unknown pyx12 error code "%s" (not in pyx12.error_codes.ERROR_CODES)' % (self.err_cde) )