Yaml export errors now don't show stacktrace

This commit is contained in:
apainintheneck 2022-04-20 13:25:13 -07:00
parent 6a12853b65
commit 691186f3c5
2 changed files with 10 additions and 8 deletions

View file

@ -35,6 +35,9 @@ class TextExporter:
return f"[Journal exported to {path}]" return f"[Journal exported to {path}]"
except IOError as e: except IOError as e:
return f"[{ERROR_COLOR}ERROR{RESET_COLOR}: {e.filename} {e.strerror}]" return f"[{ERROR_COLOR}ERROR{RESET_COLOR}: {e.filename} {e.strerror}]"
except RuntimeError as e:
os.remove(path)
return e
@classmethod @classmethod
def make_filename(cls, entry): def make_filename(cls, entry):
@ -54,6 +57,9 @@ class TextExporter:
return "[{2}ERROR{3}: {0} {1}]".format( return "[{2}ERROR{3}: {0} {1}]".format(
e.filename, e.strerror, ERROR_COLOR, RESET_COLOR e.filename, e.strerror, ERROR_COLOR, RESET_COLOR
) )
except RuntimeError as e:
os.remove(full_path)
return e
return "[Journal exported to {}]".format(path) return "[Journal exported to {}]".format(path)
def _slugify(string): def _slugify(string):

View file

@ -23,12 +23,10 @@ class YAMLExporter(TextExporter):
def export_entry(cls, entry, to_multifile=True): def export_entry(cls, entry, to_multifile=True):
"""Returns a markdown representation of a single entry, with YAML front matter.""" """Returns a markdown representation of a single entry, with YAML front matter."""
if to_multifile is False: if to_multifile is False:
print( raise RuntimeError(
f"{ERROR_COLOR}ERROR{RESET_COLOR}: YAML export must be to individual files. Please \ f"{ERROR_COLOR}ERROR{RESET_COLOR}: YAML export must be to individual files. Please \
specify a directory to export to.", specify a directory to export to."
file=sys.stderr,
) )
return
date_str = entry.date.strftime(entry.journal.config["timeformat"]) date_str = entry.date.strftime(entry.journal.config["timeformat"])
body_wrapper = "\n" if entry.body else "" body_wrapper = "\n" if entry.body else ""
@ -131,10 +129,8 @@ class YAMLExporter(TextExporter):
@classmethod @classmethod
def export_journal(cls, journal): def export_journal(cls, journal):
"""Returns an error, as YAML export requires a directory as a target.""" """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{}: YAML export must be to individual files. Please specify a directory to export to.".format(
ERROR_COLOR, RESET_COLOR ERROR_COLOR, RESET_COLOR
), )
file=sys.stderr,
) )
return