A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: fix crash on rewriting error message
Abdullah Attaaece1404735b
diff --git a/apps/desktop/src/api/sqlite-kysely.ts b/apps/desktop/src/api/sqlite-kysely.tsindex d3726ede1..c63207ab6 100644--- a/apps/desktop/src/api/sqlite-kysely.ts+++ b/apps/desktop/src/api/sqlite-kysely.ts@@ -113,7 +113,8 @@ export class SQLite {};}} catch (e) {- if (e instanceof Error) e.message += ` (query: ${sql})`;+ if (e instanceof Error)+ throw rewriteError(e, `${e.message} (query: ${sql})`);throw e;} finally {// Since SQLite 3.48.0 (SQLite3MC v2.0.2) it's not possible to load fts5@@ -212,3 +213,11 @@ function getExtensionPath(extensionName: string, entryPoint: string) {}return loadablePath;}++function rewriteError(e: Error, message: string) {+ const error = new Error(message);+ error.stack = e.stack;+ error.name = e.name;+ error.cause = e.cause;+ return error;+}diff --git a/apps/web/src/common/sqlite/sqlite.worker.ts b/apps/web/src/common/sqlite/sqlite.worker.tsindex 36929cf03..7d719d286 100644--- a/apps/web/src/common/sqlite/sqlite.worker.ts+++ b/apps/web/src/common/sqlite/sqlite.worker.ts@@ -26,6 +26,7 @@ import { DatabaseSource } from "./sqlite-export";import { createSharedServicePort } from "./shared-service";import type { IDBBatchAtomicVFS } from "./IDBBatchAtomicVFS";import type { AccessHandlePoolVFS } from "./AccessHandlePoolVFS";+import { rewriteError } from "../../utils/error";type PreparedStatement = {stmt: number;@@ -146,7 +147,7 @@ class _SQLiteWorker {return rows;} catch (e) {if (e instanceof Error || e instanceof SQLiteError)- e.message += ` (error exec query: ${sql})`;+ throw rewriteError(e, `${e.message} (error executing query: ${sql})`);throw e;} finally {await this.sqlitediff --git a/apps/web/src/utils/error.ts b/apps/web/src/utils/error.tsnew file mode 100644index 000000000..b21e138e4--- /dev/null+++ b/apps/web/src/utils/error.ts@@ -0,0 +1,26 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++export function rewriteError(e: Error, message: string) {+ const error = new Error(message);+ error.stack = e.stack;+ error.name = e.name;+ error.cause = e.cause;+ return error;+}