kopia lustrzana https://github.com/simonw/datasette
Write errors to stderr, closes #1131
rodzic
42efb799ea
commit
eae103a82b
|
@ -1,8 +1,8 @@
|
|||
import asyncio
|
||||
import contextlib
|
||||
from pathlib import Path
|
||||
import janus
|
||||
import queue
|
||||
import sys
|
||||
import threading
|
||||
import uuid
|
||||
|
||||
|
@ -104,7 +104,8 @@ class Database:
|
|||
try:
|
||||
result = task.fn(conn)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
sys.stderr.write("{}\n".format(e))
|
||||
sys.stderr.flush()
|
||||
result = e
|
||||
task.reply_queue.sync_q.put(result)
|
||||
|
||||
|
@ -156,11 +157,12 @@ class Database:
|
|||
if e.args == ("interrupted",):
|
||||
raise QueryInterrupted(e, sql, params)
|
||||
if log_sql_errors:
|
||||
print(
|
||||
"ERROR: conn={}, sql = {}, params = {}: {}".format(
|
||||
sys.stderr.write(
|
||||
"ERROR: conn={}, sql = {}, params = {}: {}\n".format(
|
||||
conn, repr(sql), params, e
|
||||
)
|
||||
)
|
||||
sys.stderr.flush()
|
||||
raise
|
||||
|
||||
if truncate:
|
||||
|
|
|
@ -20,7 +20,6 @@ def convert_specific_columns_to_json(rows, columns, json_cols):
|
|||
try:
|
||||
value = json.loads(value)
|
||||
except (TypeError, ValueError) as e:
|
||||
print(e)
|
||||
pass
|
||||
new_row.append(value)
|
||||
new_rows.append(new_row)
|
||||
|
|
|
@ -2,6 +2,7 @@ import asyncio
|
|||
import csv
|
||||
import hashlib
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import urllib
|
||||
|
||||
|
@ -362,7 +363,8 @@ class DataView(BaseView):
|
|||
new_row.append(cell)
|
||||
await writer.writerow(new_row)
|
||||
except Exception as e:
|
||||
print("caught this", e)
|
||||
sys.stderr.write("Caught this error: {}\n".format(e))
|
||||
sys.stderr.flush()
|
||||
await r.write(str(e))
|
||||
return
|
||||
|
||||
|
|
|
@ -214,3 +214,10 @@ def test_config_deprecated(ensure_eventloop):
|
|||
assert result.exit_code == 0
|
||||
assert not json.loads(result.output)["allow_download"]
|
||||
assert "will be deprecated in" in result.stderr
|
||||
|
||||
|
||||
def test_sql_errors_logged_to_stderr(ensure_eventloop):
|
||||
runner = CliRunner(mix_stderr=False)
|
||||
result = runner.invoke(cli, ["--get", "/:memory:.json?sql=select+blah"])
|
||||
assert result.exit_code == 1
|
||||
assert "sql = 'select blah', params = {}: no such column: blah\n" in result.stderr
|
||||
|
|
Ładowanie…
Reference in New Issue