Skip to content

Commit

Permalink
Show more detailed error on invalid JSON, closes #532
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed May 8, 2023
1 parent a256d7d commit e4ed372
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions sqlite_utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,9 +994,11 @@ def insert_upsert_implementation(
docs = json.load(decoded)
if isinstance(docs, dict):
docs = [docs]
except json.decoder.JSONDecodeError:
except json.decoder.JSONDecodeError as ex:
raise click.ClickException(
"Invalid JSON - use --csv for CSV or --tsv for TSV files"
"Invalid JSON - use --csv for CSV or --tsv for TSV files\n\nJSON error: {}".format(
ex
)
)
if flatten:
docs = (_flatten(doc) for doc in docs)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def test_insert_invalid_json_error(tmpdir):
input="name,age\nCleo,4",
)
assert result.exit_code == 1
assert (
result.output
== "Error: Invalid JSON - use --csv for CSV or --tsv for TSV files\n"
assert result.output == (
"Error: Invalid JSON - use --csv for CSV or --tsv for TSV files\n\n"
"JSON error: Expecting value: line 1 column 1 (char 0)\n"
)


Expand Down

0 comments on commit e4ed372

Please sign in to comment.