Skip to content

Commit acb5a56

Browse files
committed
Catch database errors also on schema initialization
In case any database error occurs on opening the connection and initializing the schema, catch the error and throw it properly. For instance, this can happen if the database is locked on opening.
1 parent ef682aa commit acb5a56

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

logstash_async/database.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ def _close(self):
5555
# ----------------------------------------------------------------------
5656
def _initialize_schema(self):
5757
cursor = self._connection.cursor()
58-
for statement in DATABASE_SCHEMA_STATEMENTS:
59-
cursor.execute(statement)
58+
try:
59+
for statement in DATABASE_SCHEMA_STATEMENTS:
60+
cursor.execute(statement)
61+
except sqlite3.OperationalError:
62+
self._close()
63+
self._handle_sqlite_error()
64+
raise
6065

6166
# ----------------------------------------------------------------------
6267
def add_event(self, event):

0 commit comments

Comments
 (0)