2021-09-08 20:39:14 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-03-02 17:59:18 +00:00
|
|
|
export enum SqliteErrorKind {
|
2023-10-10 23:19:11 +00:00
|
|
|
Corrupted = 'Corrupted',
|
|
|
|
Readonly = 'Readonly',
|
|
|
|
Unknown = 'Unknown',
|
2023-03-02 17:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2021-09-08 20:39:14 +00:00
|
|
|
}
|