From 8d5b70a219993515f156992099818914378db2fc Mon Sep 17 00:00:00 2001 From: Anders K Date: Wed, 1 Jun 2022 19:33:31 +0000 Subject: [PATCH] Throw errors, not strings --- src/api.js | 20 ++++++++++---------- src/worker.js | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/api.js b/src/api.js index 854bf32e..0cc5b166 100644 --- a/src/api.js +++ b/src/api.js @@ -311,11 +311,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { * @param {Statement.BindParams} values The values to bind * @return {boolean} true if it worked - * @throws {String} SQLite Error + * @throws {Error} SQLite Error */ Statement.prototype["bind"] = function bind(values) { if (!this.stmt) { - throw "Statement closed"; + throw new Error("Statement closed"); } this["reset"](); if (Array.isArray(values)) return this.bindFromArray(values); @@ -329,11 +329,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { that can be retrieved with {@link Statement.get}. @return {boolean} true if a row of result available - @throws {String} SQLite Error + @throws {Error} SQLite Error */ Statement.prototype["step"] = function step() { if (!this.stmt) { - throw "Statement closed"; + throw new Error("Statement closed"); } this.pos = 1; var ret = sqlite3_step(this.stmt); @@ -606,7 +606,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { default: break; } - throw ( + throw new Error( "Wrong API use : tried to bind a value of an unknown type (" + val + ")." ); @@ -738,7 +738,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { /** Prepare the next available SQL statement @return {StatementIterator.StatementIteratorResult} - @throws {String} SQLite error or invalid iterator error + @throws {Error} SQLite error or invalid iterator error */ StatementIterator.prototype["next"] = function next() { if (this.sqlPtr === null) { @@ -847,7 +847,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { */ Database.prototype["run"] = function run(sql, params) { if (!this.db) { - throw "Database closed"; + throw new Error("Database closed"); } if (params) { var stmt = this["prepare"](sql, params); @@ -930,7 +930,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { */ Database.prototype["exec"] = function exec(sql, params, config) { if (!this.db) { - throw "Database closed"; + throw new Error("Database closed"); } var stack = stackSave(); var stmt = null; @@ -1028,7 +1028,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { (`?`, `:VVV`, `:AAA`, `@AAA`) @param {Statement.BindParams} [params] values to bind to placeholders @return {Statement} the resulting statement - @throws {String} SQLite error + @throws {Error} SQLite error */ Database.prototype["prepare"] = function prepare(sql, params) { setValue(apiTemp, 0, "i32"); @@ -1036,7 +1036,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { // pointer to a statement, or null var pStmt = getValue(apiTemp, "i32"); if (pStmt === NULL) { - throw "Nothing to prepare"; + throw new Error("Nothing to prepare"); } var stmt = new Statement(pStmt, this); if (params != null) { diff --git a/src/worker.js b/src/worker.js index f75bf6a1..99ef7e73 100644 --- a/src/worker.js +++ b/src/worker.js @@ -29,7 +29,7 @@ function onModuleReady(SQL) { createDb(); } if (!data["sql"]) { - throw "exec: Missing query string"; + throw new Error("exec: Missing query string"); } return postMessage({ id: data["id"],