Skip to content

Commit

Permalink
feat: raise any httpx exceptions, e.g. from failed auth
Browse files Browse the repository at this point in the history
This means that 403s, such as those from not being allowed to fetch a specific
version, are passed to client code, and so help debug permission errors better
than the disk i/o error that's being raised right now.

It also means there is consistency - before this change if there's a 403 (or
any other connection error) from the initial HEAD request on the start of a
query, then that was being passed to client now. Now, during the read data
during the query if these get raised they get passed to client code.
  • Loading branch information
michalc committed Mar 15, 2024
1 parent 92267ea commit 79b8b7a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions sqlite_s3_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,25 @@ def sqlite_s3_query_multi(url, get_credentials=lambda now: (
body_hash = sha256(b'').hexdigest()
scheme, netloc, path, _, _ = urlsplit(url)

pending_exception = None

def raise_any_pending_exception():
nonlocal pending_exception
if pending_exception is not None:
to_raise = pending_exception
pending_exception = None
raise to_raise

def run(func, *args):
res = func(*args)
raise_any_pending_exception()
if res != 0:
raise SQLiteError(libsqlite3.sqlite3_errstr(res).decode())

def run_with_db(db, func, *args):
if func(*args) != 0:
res = func(*args)
raise_any_pending_exception()
if res != 0:
raise SQLiteError(libsqlite3.sqlite3_errmsg(db).decode())

@contextmanager
Expand Down Expand Up @@ -169,6 +181,7 @@ def x_close(p_file):

x_read_type = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int64)
def x_read(p_file, p_out, i_amt, i_ofst):
nonlocal pending_exception
offset = 0

try:
Expand All @@ -183,7 +196,8 @@ def x_read(p_file, p_out, i_amt, i_ofst):
offset += len(chunk)
if offset > i_amt:
break
except Exception:
except Exception as exception:
pending_exception = exception
return SQLITE_IOERR

if offset != i_amt:
Expand Down

0 comments on commit 79b8b7a

Please sign in to comment.