Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw errors, not strings #514

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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 + ")."
);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1028,15 +1028,15 @@ 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");
this.handleError(sqlite3_prepare_v2(this.db, sql, -1, apiTemp, NULL));
// 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) {
Expand Down
2 changes: 1 addition & 1 deletion src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down