Graceful handling of readonly DB error
This commit is contained in:
parent
1e7d658109
commit
bd40a7fb98
4 changed files with 98 additions and 27 deletions
|
@ -1,11 +1,32 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
export function isCorruptionError(error?: Error): boolean {
|
||||
return (
|
||||
error?.message?.includes('SQLITE_CORRUPT') ||
|
||||
error?.message?.includes('database disk image is malformed') ||
|
||||
error?.message?.includes('file is not a database') ||
|
||||
false
|
||||
);
|
||||
export enum SqliteErrorKind {
|
||||
Corrupted,
|
||||
Readonly,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
export function parseSqliteError(error?: Error): SqliteErrorKind {
|
||||
const message = error?.message;
|
||||
if (!message) {
|
||||
return SqliteErrorKind.Unknown;
|
||||
}
|
||||
|
||||
if (
|
||||
message.includes('SQLITE_CORRUPT') ||
|
||||
message.includes('database disk image is malformed') ||
|
||||
message.includes('file is not a database')
|
||||
) {
|
||||
return SqliteErrorKind.Corrupted;
|
||||
}
|
||||
|
||||
if (
|
||||
message.includes('SQLITE_READONLY') ||
|
||||
message.includes('attempt to write a readonly database')
|
||||
) {
|
||||
return SqliteErrorKind.Readonly;
|
||||
}
|
||||
|
||||
return SqliteErrorKind.Unknown;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue