Skip to content

Commit 2e83a02

Browse files
committed
Make error handling more robust to python configuration
1 parent 59c1960 commit 2e83a02

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

jupyter_server/base/handlers.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import mimetypes
1212
import os
1313
import re
14-
import sqlite3
1514
import types
1615
import warnings
1716
from http.client import responses
@@ -37,6 +36,7 @@
3736
from jupyter_server.utils import (
3837
ensure_async,
3938
filefind,
39+
is_sqlite_disk_full_error,
4040
url_escape,
4141
url_is_absolute,
4242
url_path_join,
@@ -766,12 +766,9 @@ def write_error(self, status_code: int, **kwargs: Any) -> None:
766766
if isinstance(e, HTTPError):
767767
reply["message"] = e.log_message or message
768768
reply["reason"] = e.reason
769-
elif (
770-
isinstance(e, sqlite3.OperationalError)
771-
and e.sqlite_errorcode == sqlite3.SQLITE_FULL
772-
):
769+
elif is_sqlite_disk_full_error(e):
773770
reply["message"] = "Disk is full"
774-
reply["reason"] = e.sqlite_errorname
771+
reply["reason"] = str(e)
775772
else:
776773
reply["message"] = "Unhandled error"
777774
reply["reason"] = None

jupyter_server/utils.py

+9
Original file line numberDiff line numberDiff line change
@@ -433,3 +433,12 @@ class JupyterServerAuthWarning(RuntimeWarning):
433433
Intended for filtering out expected warnings in tests, including
434434
downstream tests, rather than for users to silence this warning.
435435
"""
436+
437+
438+
def is_sqlite_disk_full_error(e: Exception) -> bool:
439+
try:
440+
import sqlite3
441+
442+
return isinstance(e, sqlite3.OperationalError) and e.sqlite_errorcode == sqlite3.SQLITE_FULL
443+
except (AttributeError, ImportError) as e:
444+
return "database or disk is full" in str(e)

0 commit comments

Comments
 (0)