Skip to content

Commit

Permalink
CLI: more useful error messages on JSON formatting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lonvia committed Aug 16, 2024
1 parent 8e8f7a6 commit d648561
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/nominatim_db/clicmd/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,17 @@ def _print_output(formatter: napi.FormatDispatcher, result: Any,
output = formatter.format_result(result, fmt, options)
if formatter.get_content_type(fmt) == CONTENT_JSON:
# reformat the result, so it is pretty-printed
json.dump(json.loads(output), sys.stdout, indent=4, ensure_ascii=False)
try:
json.dump(json.loads(output), sys.stdout, indent=4, ensure_ascii=False)
except json.decoder.JSONDecodeError as err:
# Catch the error here, so that data can be debugged,
# when people are developping custom result formatters.
LOG.fatal("Parsing json failed: %s\nUnformatted output:\n%s", err, output)
else:
sys.stdout.write(output)
sys.stdout.write('\n')


class APISearch:
"""\
Execute a search query.
Expand Down

0 comments on commit d648561

Please sign in to comment.