diff --git a/qutebrowser/misc/sql.py b/qutebrowser/misc/sql.py index 0f4baac55..4c300a3da 100644 --- a/qutebrowser/misc/sql.py +++ b/qutebrowser/misc/sql.py @@ -89,12 +89,13 @@ def raise_sqlite_error(msg, error): """Raise either a SqlBugError or SqlEnvironmentError.""" error_code = error.nativeErrorCode() database_text = error.databaseText() + driver_text = error.driverText() log.sql.debug("SQL error:") log.sql.debug("type: {}".format( debug.qenum_key(QSqlError, error.type()))) log.sql.debug("database text: {}".format(database_text)) - log.sql.debug("driver text: {}".format(error.driverText())) + log.sql.debug("driver text: {}".format(driver_text)) log.sql.debug("error code: {}".format(error_code)) environmental_errors = [ @@ -105,18 +106,15 @@ def raise_sqlite_error(msg, error): SqliteErrorCode.FULL, SqliteErrorCode.CANTOPEN, ] - # At least in init(), we can get errors like this: - # > type: ConnectionError - # > database text: out of memory - # > driver text: Error opening database - # > error code: -1 - environmental_strings = [ - "out of memory", - ] - if (error_code in environmental_errors or - (error_code == SqliteErrorCode.UNKNOWN and - database_text in environmental_strings)): + # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-70506 + # We don't know what the actual error was, but let's assume it's not us to + # blame... Usually this is something like an unreadable database file. + qtbug_70506 = (error_code == SqliteErrorCode.UNKNOWN and + driver_text == "Error opening database" and + database_text == "out of memory") + + if error_code in environmental_errors or qtbug_70506: raise SqlEnvironmentError(msg, error) else: raise SqlBugError(msg, error) diff --git a/tests/unit/misc/test_sql.py b/tests/unit/misc/test_sql.py index 149d44a98..54c785286 100644 --- a/tests/unit/misc/test_sql.py +++ b/tests/unit/misc/test_sql.py @@ -49,9 +49,13 @@ 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", + def test_qtbug_70506(self): + """Test Qt's wrong handling of errors while opening the database. + + Due to https://bugreports.qt.io/browse/QTBUG-70506 we get an error with + "out of memory" as string and -1 as error code. + """ + sql_err = QSqlError("Error opening database", "out of memory", QSqlError.UnknownError, sql.SqliteErrorCode.UNKNOWN)