mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
CLI: more useful error messages on JSON formatting errors
This commit is contained in:
@@ -122,11 +122,17 @@ def _print_output(formatter: napi.FormatDispatcher, result: Any,
|
|||||||
output = formatter.format_result(result, fmt, options)
|
output = formatter.format_result(result, fmt, options)
|
||||||
if formatter.get_content_type(fmt) == CONTENT_JSON:
|
if formatter.get_content_type(fmt) == CONTENT_JSON:
|
||||||
# reformat the result, so it is pretty-printed
|
# 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:
|
else:
|
||||||
sys.stdout.write(output)
|
sys.stdout.write(output)
|
||||||
sys.stdout.write('\n')
|
sys.stdout.write('\n')
|
||||||
|
|
||||||
|
|
||||||
class APISearch:
|
class APISearch:
|
||||||
"""\
|
"""\
|
||||||
Execute a search query.
|
Execute a search query.
|
||||||
|
|||||||
Reference in New Issue
Block a user