Skip to content

Commit

Permalink
Make error handling more robust to python configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
nmdanny committed Jul 30, 2024
1 parent 59c1960 commit 2e83a02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 3 additions & 6 deletions jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import mimetypes
import os
import re
import sqlite3
import types
import warnings
from http.client import responses
Expand All @@ -37,6 +36,7 @@
from jupyter_server.utils import (
ensure_async,
filefind,
is_sqlite_disk_full_error,
url_escape,
url_is_absolute,
url_path_join,
Expand Down Expand Up @@ -766,12 +766,9 @@ def write_error(self, status_code: int, **kwargs: Any) -> None:
if isinstance(e, HTTPError):
reply["message"] = e.log_message or message
reply["reason"] = e.reason
elif (
isinstance(e, sqlite3.OperationalError)
and e.sqlite_errorcode == sqlite3.SQLITE_FULL
):
elif is_sqlite_disk_full_error(e):
reply["message"] = "Disk is full"
reply["reason"] = e.sqlite_errorname
reply["reason"] = str(e)
else:
reply["message"] = "Unhandled error"
reply["reason"] = None
Expand Down
9 changes: 9 additions & 0 deletions jupyter_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,12 @@ class JupyterServerAuthWarning(RuntimeWarning):
Intended for filtering out expected warnings in tests, including
downstream tests, rather than for users to silence this warning.
"""


def is_sqlite_disk_full_error(e: Exception) -> bool:
try:
import sqlite3

return isinstance(e, sqlite3.OperationalError) and e.sqlite_errorcode == sqlite3.SQLITE_FULL
except (AttributeError, ImportError) as e:
return "database or disk is full" in str(e)

0 comments on commit 2e83a02

Please sign in to comment.