Skip to content

sqlite3 - preserve error information from a user-defined function exception #98893

Closed as not planned
@pchemguy

Description

@pchemguy

In accordance with sqlite3.enable_callback_tracebacks documentation, "By default you will not get any tracebacks in user-defined functions, aggregates, converters, authorizer callbacks etc." While it is possible to retrieve debugging information via sqlite3.enable_callback_tracebacks & sys.unraisablehook, often it would be sufficient to append the exception message to the canned response, avoiding the need for extra efforts. For example, the problem in the following code is clearly indicated by the actual exception message, whereas the canned message is not nearly as helpful:

import sqlite3

con = sqlite3.connect(":memory:")
con.create_function("dummy", 0, lambda __: 1)
sqlite3.enable_callback_tracebacks(True)  # Provides error details to stderr
try:
    con.execute("SELECT dummy();")
except sqlite3.OperationalError as err:
    print(err)  # Error details are not available, only a canned message.

As pointed out in this SO answer, it should be possible to appended the actual exception message to the canned response in the code block that processes the sqlite3.enable_callback_tracebacks flag.

Linked PRs

Metadata

Metadata

Labels

Projects

Status

Discarded

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions