cli: Print compile errors to stderr

This commit is contained in:
Sonny Piers 2023-01-05 00:51:02 +01:00
parent 59aa054c4c
commit 40f493b378
2 changed files with 4 additions and 4 deletions

View file

@ -28,7 +28,7 @@ class PrintableError(Exception):
"""Parent class for errors that can be pretty-printed for the user, e.g. """Parent class for errors that can be pretty-printed for the user, e.g.
compilation warnings and errors.""" compilation warnings and errors."""
def pretty_print(self, filename, code): def pretty_print(self, filename, code, stream=sys.stdout):
raise NotImplementedError() raise NotImplementedError()
@ -144,9 +144,9 @@ class MultipleErrors(PrintableError):
super().__init__() super().__init__()
self.errors = errors self.errors = errors
def pretty_print(self, filename, code) -> None: def pretty_print(self, filename, code, stream=sys.stdout) -> None:
for error in self.errors: for error in self.errors:
error.pretty_print(filename, code) error.pretty_print(filename, code, stream)
if len(self.errors) != 1: if len(self.errors) != 1:
print(f"{len(self.errors)} errors") print(f"{len(self.errors)} errors")

View file

@ -104,7 +104,7 @@ class BlueprintApp:
with open(opts.output, "w") as file: with open(opts.output, "w") as file:
file.write(xml) file.write(xml)
except PrintableError as e: except PrintableError as e:
e.pretty_print(opts.input.name, data) e.pretty_print(opts.input.name, data, stream=sys.stderr)
sys.exit(1) sys.exit(1)
def cmd_batch_compile(self, opts): def cmd_batch_compile(self, opts):