Skip to content

Improve error reporting #99

@dmalan

Description

@dmalan

Currently, a syntax error (e.g., a missing paren) might yield this output from SQL.execute, with the DEBUG line in red:

DEBUG:cs50:INSERT INTO tbl (id, foo VALUES(1, NULL)
Traceback (most recent call last):
  File "foo.py", line 8, in <module>
    print(db.execute("INSERT INTO tbl (id, foo VALUES(1, NULL)"))
  File "/mnt/src/cs50/sql.py", line 289, in execute
    raise e
RuntimeError: (sqlite3.OperationalError) near "VALUES": syntax error
[SQL: INSERT INTO tbl (id, foo VALUES(1, NULL)]
(Background on this error at: http://sqlalche.me/e/e3q8)

Could be simplified to:

DEBUG:cs50:INSERT INTO tbl (id, foo VALUES(1, NULL)
Traceback (most recent call last):
  File "foo.py", line 8, in <module>
    print(db.execute("INSERT INTO tbl (id, foo VALUES(1, NULL)"))
  File "/mnt/src/cs50/sql.py", line 289, in execute
    raise e
RuntimeError: near "VALUES": syntax error

Meanwhile, an IntegrityError yields the below, with the DEBUG line in yellow, but doesn't report the actual issue:

DEBUG:cs50:INSERT INTO tbl (id, foo) VALUES(1, NULL)

This could be enhanced as follows, with the first DEBUG line in yellow, the second in white (since it's not a query):

DEBUG:cs50:INSERT INTO tbl (id, foo) VALUES(1, NULL)
DEBUG:cs50:NOT NULL constraint failed: tbl.foo

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions