Fix handling of sqlite out of memory errors

The "error_code == -1" check never passed, as error_code (confusingly) is a
string of a number.
This commit is contained in:
Florian Bruhin 2018-09-12 01:36:50 +02:00
parent c8b447daec
commit c2a072f9fe
2 changed files with 12 additions and 1 deletions

View File

@ -35,6 +35,7 @@ class SqliteErrorCode:
in qutebrowser here.
"""
UNKNOWN = '-1'
BUSY = '5' # database is locked
READONLY = '8' # attempt to write a readonly database
IOERR = '10' # disk I/O error
@ -114,7 +115,8 @@ def raise_sqlite_error(msg, error):
]
if (error_code in environmental_errors or
(error_code == -1 and database_text in environmental_strings)):
(error_code == SqliteErrorCode.UNKNOWN and
database_text in environmental_strings)):
raise SqlEnvironmentError(msg, error)
else:
raise SqlBugError(msg, error)

View File

@ -49,6 +49,15 @@ class TestSqlError:
with pytest.raises(exception):
sql.raise_sqlite_error("Message", sql_err)
def test_out_of_memory(self):
"""On out of memory error, we get an error code '-1' from Qt."""
sql_err = QSqlError("driver text",
"out of memory",
QSqlError.UnknownError,
sql.SqliteErrorCode.UNKNOWN)
with pytest.raises(sql.SqlEnvironmentError):
sql.raise_sqlite_error("Message", sql_err)
def test_logging(self, caplog):
sql_err = QSqlError("driver text", "db text", QSqlError.UnknownError,
'23')