Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: improve error reporting if a query fails

Abdullah Atta0b3060e4c008
diff --git a/apps/web/src/common/sqlite/sqlite.worker.ts b/apps/web/src/common/sqlite/sqlite.worker.ts
index 243eb51b8..c4f253836 100644
--- a/apps/web/src/common/sqlite/sqlite.worker.ts
+++ b/apps/web/src/common/sqlite/sqlite.worker.ts
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import type { SQLiteAPI, SQLiteCompatibleType } from "./sqlite-types";
-import { Factory, SQLITE_ROW } from "./sqlite-api";
+import { Factory, SQLITE_ROW, SQLiteError } from "./sqlite-api";
import { transfer } from "comlink";
import type { RunMode } from "./type";
import { QueryResult } from "kysely";
@@ -97,6 +97,8 @@ async function prepare(sql: string) {
return prepare(sql);
} else retryCounter[sql] = 0;
+ if (ex instanceof Error || ex instanceof SQLiteError)
+ ex.message += ` (query: ${sql})`;
throw ex;
}
}
@@ -126,6 +128,10 @@ async function run(
}
return rows;
+ } catch (e) {
+ if (e instanceof Error || e instanceof SQLiteError)
+ e.message += ` (query: ${sql})`;
+ throw e;
} finally {
await sqlite
.reset(prepared.stmt)
diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.ts
index 3b03434f7..909bae920 100644
--- a/apps/web/src/stores/editor-store.ts
+++ b/apps/web/src/stores/editor-store.ts
@@ -802,7 +802,9 @@ class EditorStore extends BaseStore<EditorStore> {
} catch (err) {
showToast(
"error",
- err instanceof Error ? err.stack || err.message : JSON.stringify(err)
+ err instanceof Error && err.stack
+ ? err.message + err.stack
+ : JSON.stringify(err)
);
this.setSaveState(id, SaveState.NotSaved);
console.error(err);