File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -182,8 +182,8 @@ export default class SqliteHandler {
182182 // If we get an invalid list token, we'll delete the token and
183183 // clear the DB and try again without a token.
184184 if (
185- err ?. errors [ 0 ] . status === 400 &&
186- err ?. errors [ 0 ] . code === 'invalid list token'
185+ err ?. errors ?. [ 0 ] . status === 400 &&
186+ err ?. errors ?. [ 0 ] . code === 'invalid list token'
187187 ) {
188188 await this . sqlite . deleteResource ( type ) ;
189189 // Delete all tokens of the same resource type so we don't keep clearing the DB.
Original file line number Diff line number Diff line change @@ -27,6 +27,10 @@ const MAX_HOST_PARAMETERS = 32766;
2727const SCHEMA_VERSION = 1 ;
2828const isSecure = self . isSecureContext ;
2929
30+ // Error code for sqlite corruption errors.
31+ // See https://sqlite.org/rescode.html#corrupt
32+ const SQLITE_CORRUPT = 11 ;
33+
3034const methods = {
3135 initializeSQLite : async ( ) => {
3236 sqlite3 = await sqlite3InitModule ( {
@@ -65,7 +69,7 @@ const methods = {
6569
6670 setupDb ( ) ;
6771 done = true ;
68- } catch ( err ) {
72+ } catch ( /** @type { import('@sqlite.org/sqlite-wasm').SQLite3Error } */ err ) {
6973 // If we get a SQLite3Error and the pool is at capacity, we'll assume the error is
7074 // because we hit the cap so we add more capacity and see if that solves it.
7175 if (
@@ -81,7 +85,13 @@ const methods = {
8185 }
8286 } else {
8387 console . error ( 'SQLite initialization error:' , err ) ;
84- throw err ;
88+
89+ // We might have gotten ourselves into a bad state which corrupted the DB so clear it out and retry
90+ if ( err ?. resultCode === SQLITE_CORRUPT ) {
91+ poolUtil . unlink ( `/${ dbName } ` ) ;
92+ } else {
93+ throw err ;
94+ }
8595 }
8696 }
8797 }
You can’t perform that action at this time.
0 commit comments