omnilib / aiosqlite

asyncio bridge to the standard sqlite3 module

Home Page:https://aiosqlite.omnilib.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stop logging "returning exception"

Lonami opened this issue · comments

Every time an exception occurs, the following line is logged if logging is enabled:

except BaseException as e:
LOG.exception("returning exception %s", e)

This is bad because the library can and does propagate the error:

get_loop(future).call_soon_threadsafe(future.set_exception, e)

The user code will handle it, there is no need to log it unless the library could not pass it to the user's code. If the user code wants to log it, that's their job. Maybe the INFO level would be more appropriated "hey, an error occured and I am informing that I will hand it over to user's code". Not ERROR, it works fine!

In my use case I am doing this:

try:
    tup = await db.execute("SELECT * FROM Version")
except sqlite3.OperationalError:
    await create_tables(db)

I try to select from the version table, and if said table is missing I ask for forgiveness by excepting the error. This behaviour is correct, but aiosqlite is logging an error that shouldn't.

I got fed up with these logs when I am using sqlite3 correctly and handling expected errors like uniqueness constraints inside my application. Unfortunately, my only temporary solution was to tell aiosqlite logging to get bent. I would like to not do this and will follow this issue for a better resolution.

Edit: removed my hack solution; thanks for fixing this!