######################################################################
# 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 .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",
)
[docs]
seg_errors = ("1", "2", "3", "4", "5", "6", "7", "8")
[docs]
ele_errors = ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")
@dataclass(slots=True, frozen=True)
@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]
seg_count: int | None = None
[docs]
ls_id: str | None = None
def __post_init__(self) -> None:
if self.err_cde not in seg_errors:
raise EngineError('Invalid segment level error code "%s"' % (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).
def __post_init__(self) -> None:
if self.err_cde not in ele_errors:
raise EngineError('Invalid element level error code "%s"' % (self.err_cde))