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

cli: handle deserialization errors #72

Merged
merged 2 commits into from
Sep 6, 2023

Conversation

corytodd
Copy link
Collaborator

@corytodd corytodd commented Sep 5, 2023

For the CLI tool, typical user input should not produce stack traces. Show appropriate messages when one or both file
inputs are invalid or do not exist. This implementation respects the current API by not introducing a unified exception
type directly in the loader implementations. Current library consumers should not be broken by this change but cli users
should see a prettier output when things go wrong.

Fixes #71

Cory Todd added 2 commits September 5, 2023 14:22
We have never handled the JSONDecodeError so consumers are assumed to
be catching that exception on their end. This means we cannot wrap all
the parser errors into a unified type (e.g. ValueError) without breaking
the API. Keep API compatibility on the loader functions by introducing a
Serializer class that the cli tool can utilize. This allows the cli to
avoid knowing which specific serializer errors to handle. The library
itself maintains its current API.

Signed-off-by: Cory Todd <cory.todd@canonical.com>
Do not show a stacktrace on the cli tool when an invalid file is
specified. Instead, use the new Serializer class to abstract the load
process and handle the unified ValueError. Also handle FileNotFound
because that's a fairly normal user input scenario as well. Set return
code on sys.exit to indicate abnormal exit.

Fixes xlwings#71

Signed-off-by: Cory Todd <cory.todd@canonical.com>
@corytodd corytodd merged commit 6886210 into xlwings:master Sep 6, 2023
8 checks passed
@corytodd corytodd deleted the handle-deserialization-errors branch September 6, 2023 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When giving a file that is not JSON, there's traceback output
1 participant