From 40f493b378cf73d1cc3f128895e842e8665a56c3 Mon Sep 17 00:00:00 2001 From: Sonny Piers Date: Thu, 5 Jan 2023 00:51:02 +0100 Subject: [PATCH] cli: Print compile errors to stderr --- blueprintcompiler/errors.py | 6 +++--- blueprintcompiler/main.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/blueprintcompiler/errors.py b/blueprintcompiler/errors.py index 7ddaef0..816bd4a 100644 --- a/blueprintcompiler/errors.py +++ b/blueprintcompiler/errors.py @@ -28,7 +28,7 @@ class PrintableError(Exception): """Parent class for errors that can be pretty-printed for the user, e.g. compilation warnings and errors.""" - def pretty_print(self, filename, code): + def pretty_print(self, filename, code, stream=sys.stdout): raise NotImplementedError() @@ -144,9 +144,9 @@ class MultipleErrors(PrintableError): super().__init__() 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: - error.pretty_print(filename, code) + error.pretty_print(filename, code, stream) if len(self.errors) != 1: print(f"{len(self.errors)} errors") diff --git a/blueprintcompiler/main.py b/blueprintcompiler/main.py index 4e4d378..a3a70a2 100644 --- a/blueprintcompiler/main.py +++ b/blueprintcompiler/main.py @@ -104,7 +104,7 @@ class BlueprintApp: with open(opts.output, "w") as file: file.write(xml) except PrintableError as e: - e.pretty_print(opts.input.name, data) + e.pretty_print(opts.input.name, data, stream=sys.stderr) sys.exit(1) def cmd_batch_compile(self, opts):