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.build.build.enums import PyTeXFileType
|
||||
from .hashing import md5
|
||||
from ...exceptions import PyTeXException
|
||||
from ...format.errors import PyTeXError
|
||||
from ...format.formatting_config import FormattingConfig
|
||||
from ...format.auto_format import formatter_from_file_extension
|
||||
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]]:
|
||||
if self._formatter is None:
|
||||
raise NotImplementedError # TODO
|
||||
# try:
|
||||
configs = self._formatter.format(
|
||||
target_root.path if isinstance(target_root, RelativePath) else target_root
|
||||
)
|
||||
# except Exception as e:
|
||||
# raise NotImplementedError
|
||||
try:
|
||||
configs = self._formatter.format(
|
||||
target_root.path if isinstance(target_root, RelativePath) else target_root
|
||||
)
|
||||
except PyTeXError as e:
|
||||
e.add_explanation(f'while processing {str(self.relative_path.path)}')
|
||||
raise e
|
||||
rel_configs = [
|
||||
(self._relative_path.with_name(filename), config)
|
||||
for [filename, config] in configs
|
||||
|
|
|
@ -212,18 +212,25 @@ class TexFormatter(PyTeXFormatter, ABC):
|
|||
recent_replacement = True
|
||||
break
|
||||
except PyTeXMacroError as e:
|
||||
e.add_explanation(f'in line {self.line_stream.line_number} ({self.line_stream.current_line().rstrip()})')
|
||||
pass
|
||||
e.add_explanation(
|
||||
f'in line {self.line_stream.line_number} ({self.line_stream.current_line().rstrip()})'
|
||||
)
|
||||
raise e
|
||||
self._shipout_line(self._post_process_line(
|
||||
self.line_stream.pop_line()
|
||||
))
|
||||
|
||||
def format(self, build_dir: Path, overwrite: bool = False) -> List[Tuple[str, FormattingConfig]]:
|
||||
for filename in self.output_files:
|
||||
self.open_output_stream(build_dir, filename)
|
||||
self.format_pre_header()
|
||||
self.format_header()
|
||||
self.format_post_header()
|
||||
self.format_document()
|
||||
self.close_output_stream()
|
||||
try:
|
||||
self.open_output_stream(build_dir, filename)
|
||||
self.format_pre_header()
|
||||
self.format_header()
|
||||
self.format_post_header()
|
||||
self.format_document()
|
||||
self.close_output_stream()
|
||||
except PyTeXError as e:
|
||||
e.add_explanation(f'while formatting output file {filename}')
|
||||
raise e
|
||||
return self.future_config
|
||||
|
||||
|
|
Loading…
Reference in a new issue