Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yaml export errors now don't show stack trace #1449

Merged
merged 4 commits into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions jrnl/plugins/text_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def write_file(cls, journal, path):
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:
return e

@classmethod
def make_filename(cls, entry):
Expand All @@ -54,6 +56,8 @@ def write_files(cls, journal, path):
return "[{2}ERROR{3}: {0} {1}]".format(
e.filename, e.strerror, ERROR_COLOR, RESET_COLOR
)
except RuntimeError as e:
return e
return "[Journal exported to {}]".format(path)

def _slugify(string):
Expand Down
12 changes: 4 additions & 8 deletions jrnl/plugins/yaml_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down Expand Up @@ -131,10 +129,8 @@ def export_entry(cls, entry, to_multifile=True):
@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
14 changes: 14 additions & 0 deletions tests/bdd/features/format.feature
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ Feature: Custom formats
| basic_folder.yaml |
# | basic_dayone.yaml |

Scenario Outline: Exporting YAML to nonexistent directory leads to user-friendly error with no traceback
Given we use the config "<config_file>"
And we use the password "test" if prompted
When we run "jrnl --export yaml --file nonexistent_dir"
Then the output should contain "YAML export must be to individual files"
And the output should not contain "Traceback"

Examples: configs
| config_file |
| basic_onefile.yaml |
| basic_encrypted.yaml |
| basic_folder.yaml |
| basic_dayone.yaml |

@skip_win # @todo YAML exporter does not correctly export emoji on Windows
Scenario Outline: Add a blank line to YAML export if there isn't one already
# https://github.com/jrnl-org/jrnl/issues/768
Expand Down