more context for errors
This commit is contained in:
parent
75e705c810
commit
bde5c63b01
2 changed files with 24 additions and 14 deletions
|
@ -5,6 +5,8 @@ from .relative_path import RelativePath
|
||||||
from PyTeX.format.formatterif import FormatterIF
|
from PyTeX.format.formatterif import FormatterIF
|
||||||
from PyTeX.build.build.enums import PyTeXFileType
|
from PyTeX.build.build.enums import PyTeXFileType
|
||||||
from .hashing import md5
|
from .hashing import md5
|
||||||
|
from ...exceptions import PyTeXException
|
||||||
|
from ...format.errors import PyTeXError
|
||||||
from ...format.formatting_config import FormattingConfig
|
from ...format.formatting_config import FormattingConfig
|
||||||
from ...format.auto_format import formatter_from_file_extension
|
from ...format.auto_format import formatter_from_file_extension
|
||||||
from ...format.git_version_info import GitVersionInfo
|
from ...format.git_version_info import GitVersionInfo
|
||||||
|
@ -72,12 +74,13 @@ class PyTeXSourceFile:
|
||||||
def format(self, target_root: Union[Path, RelativePath]) -> List[Tuple[RelativePath, FormattingConfig]]:
|
def format(self, target_root: Union[Path, RelativePath]) -> List[Tuple[RelativePath, FormattingConfig]]:
|
||||||
if self._formatter is None:
|
if self._formatter is None:
|
||||||
raise NotImplementedError # TODO
|
raise NotImplementedError # TODO
|
||||||
# try:
|
try:
|
||||||
configs = self._formatter.format(
|
configs = self._formatter.format(
|
||||||
target_root.path if isinstance(target_root, RelativePath) else target_root
|
target_root.path if isinstance(target_root, RelativePath) else target_root
|
||||||
)
|
)
|
||||||
# except Exception as e:
|
except PyTeXError as e:
|
||||||
# raise NotImplementedError
|
e.add_explanation(f'while processing {str(self.relative_path.path)}')
|
||||||
|
raise e
|
||||||
rel_configs = [
|
rel_configs = [
|
||||||
(self._relative_path.with_name(filename), config)
|
(self._relative_path.with_name(filename), config)
|
||||||
for [filename, config] in configs
|
for [filename, config] in configs
|
||||||
|
|
|
@ -212,18 +212,25 @@ class TexFormatter(PyTeXFormatter, ABC):
|
||||||
recent_replacement = True
|
recent_replacement = True
|
||||||
break
|
break
|
||||||
except PyTeXMacroError as e:
|
except PyTeXMacroError as e:
|
||||||
e.add_explanation(f'in line {self.line_stream.line_number} ({self.line_stream.current_line().rstrip()})')
|
e.add_explanation(
|
||||||
pass
|
f'in line {self.line_stream.line_number} ({self.line_stream.current_line().rstrip()})'
|
||||||
|
)
|
||||||
|
raise e
|
||||||
self._shipout_line(self._post_process_line(
|
self._shipout_line(self._post_process_line(
|
||||||
self.line_stream.pop_line()
|
self.line_stream.pop_line()
|
||||||
))
|
))
|
||||||
|
|
||||||
def format(self, build_dir: Path, overwrite: bool = False) -> List[Tuple[str, FormattingConfig]]:
|
def format(self, build_dir: Path, overwrite: bool = False) -> List[Tuple[str, FormattingConfig]]:
|
||||||
for filename in self.output_files:
|
for filename in self.output_files:
|
||||||
|
try:
|
||||||
self.open_output_stream(build_dir, filename)
|
self.open_output_stream(build_dir, filename)
|
||||||
self.format_pre_header()
|
self.format_pre_header()
|
||||||
self.format_header()
|
self.format_header()
|
||||||
self.format_post_header()
|
self.format_post_header()
|
||||||
self.format_document()
|
self.format_document()
|
||||||
self.close_output_stream()
|
self.close_output_stream()
|
||||||
|
except PyTeXError as e:
|
||||||
|
e.add_explanation(f'while formatting output file {filename}')
|
||||||
|
raise e
|
||||||
return self.future_config
|
return self.future_config
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue