From 691186f3c5d78d123dad7b6075d9a6d5d3224ace Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Wed, 20 Apr 2022 13:25:13 -0700 Subject: [PATCH] Yaml export errors now don't show stacktrace --- jrnl/plugins/text_exporter.py | 6 ++++++ jrnl/plugins/yaml_exporter.py | 12 ++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/jrnl/plugins/text_exporter.py b/jrnl/plugins/text_exporter.py index c9eaaf14..1662b533 100644 --- a/jrnl/plugins/text_exporter.py +++ b/jrnl/plugins/text_exporter.py @@ -35,6 +35,9 @@ class TextExporter: return f"[Journal exported to {path}]" except IOError as e: return f"[{ERROR_COLOR}ERROR{RESET_COLOR}: {e.filename} {e.strerror}]" + except RuntimeError as e: + os.remove(path) + return e @classmethod def make_filename(cls, entry): @@ -54,6 +57,9 @@ class TextExporter: return "[{2}ERROR{3}: {0} {1}]".format( e.filename, e.strerror, ERROR_COLOR, RESET_COLOR ) + except RuntimeError as e: + os.remove(full_path) + return e return "[Journal exported to {}]".format(path) def _slugify(string): diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py index 3c627cd5..8983d2e4 100644 --- a/jrnl/plugins/yaml_exporter.py +++ b/jrnl/plugins/yaml_exporter.py @@ -23,12 +23,10 @@ class YAMLExporter(TextExporter): def export_entry(cls, entry, to_multifile=True): """Returns a markdown representation of a single entry, with YAML front matter.""" if to_multifile is False: - print( + raise RuntimeError( f"{ERROR_COLOR}ERROR{RESET_COLOR}: YAML export must be to individual files. Please \ - specify a directory to export to.", - file=sys.stderr, + specify a directory to export to." ) - return date_str = entry.date.strftime(entry.journal.config["timeformat"]) body_wrapper = "\n" if entry.body else "" @@ -131,10 +129,8 @@ class YAMLExporter(TextExporter): @classmethod def export_journal(cls, journal): """Returns an error, as YAML export requires a directory as a target.""" - print( + raise RuntimeError( "{}ERROR{}: YAML export must be to individual files. Please specify a directory to export to.".format( ERROR_COLOR, RESET_COLOR - ), - file=sys.stderr, + ) ) - return