diff --git a/pyproject.toml b/pyproject.toml index 2113cdc..8ec331d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ namespaces = true # ----------------------------------------- Project Metadata ------------------------------------- # [project] -version = "0.0.0.dev47" +version = "0.0.0.dev48" name = "PySerials" dependencies = [ "jsonschema >= 4.21.0, < 5", @@ -26,8 +26,8 @@ dependencies = [ "ruamel.yaml >= 0.17.32, < 0.18", # https://yaml.readthedocs.io/en/stable/ "ruamel.yaml.string >= 0.1.1, < 1", "tomlkit >= 0.11.8, < 0.12", # https://tomlkit.readthedocs.io/en/stable/, - "MDit == 0.0.0.dev44", - "ExceptionMan == 0.0.0.dev44", + "MDit == 0.0.0.dev45", + "ExceptionMan == 0.0.0.dev45", "ProtocolMan == 0.0.0.dev2", ] requires-python = ">=3.10" diff --git a/requirements.txt b/requirements.txt index a099f8b..405b89f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,6 @@ jsonpath-ng >= 1.6.1, < 2 ruamel.yaml >= 0.17.32, < 0.18 ruamel.yaml.string >= 0.1.1, < 1 tomlkit >= 0.11.8, < 0.12 -MDit == 0.0.0.dev44 -ExceptionMan == 0.0.0.dev44 +MDit == 0.0.0.dev45 +ExceptionMan == 0.0.0.dev45 ProtocolMan == 0.0.0.dev2 \ No newline at end of file diff --git a/src/pyserials/exception/read.py b/src/pyserials/exception/read.py index 80c22d7..7622a21 100644 --- a/src/pyserials/exception/read.py +++ b/src/pyserials/exception/read.py @@ -142,9 +142,10 @@ def __init__( self.problem = cause.problem.strip() if cause.context: self.context = cause.context.strip() - self.context_line = cause.context_mark.line + 1 - self.context_column = cause.context_mark.column + 1 - self.context_data_type = cause.context_mark.name.removeprefix("<").removesuffix(">") + if cause.context_mark: + self.context_line = cause.context_mark.line + 1 + self.context_column = cause.context_mark.column + 1 + self.context_data_type = cause.context_mark.name.removeprefix("<").removesuffix(">") elif isinstance(cause, _json.JSONDecodeError): self.problem = cause.msg self.problem_line = cause.lineno diff --git a/src/pyserials/update.py b/src/pyserials/update.py index d695049..a0a59c0 100644 --- a/src/pyserials/update.py +++ b/src/pyserials/update.py @@ -203,6 +203,7 @@ def getter_function(path: str, default: Any = None, search: bool = False): raise_error( description_template=f"Code at {{path_invalid}} raised an exception: {e}\n{code_str_full}", path_invalid=current_path, + exception=e, ) def get_address_value(match: _re.Match | str, return_all_matches: bool = False, from_code: bool = False): @@ -323,7 +324,7 @@ def string_filler_unpack(match: _re.Match): values = get_address_value(path) return self._unpack_string_joiner.join([self._stringer(val) for val in values]) - def raise_error(path_invalid: str, description_template: str): + def raise_error(path_invalid: str, description_template: str, exception: Exception | None = None): raise _exception.update.PySerialsUpdateTemplatedDataError( description_template=description_template, path_invalid=path_invalid, @@ -333,7 +334,7 @@ def raise_error(path_invalid: str, description_template: str): data_source=self._data, template_start=self._marker_start_value, template_end=self._marker_end_value, - ) + ) from exception self._check_endless_loop(templ, current_chain) @@ -361,7 +362,7 @@ def raise_error(path_invalid: str, description_template: str): unpack_value = fill_nested_values(unpack_value) submatch_list = self._pattern_list.fullmatch(unpack_value) if submatch_list: - return get_address_value(unpack_value, return_all_matches=True) + return get_address_value(submatch_list, return_all_matches=True) return get_address_value(unpack_value) # Handle strings code_blocks_filled = self._pattern_code.sub(