diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 0eccb2f7103563..a6717853e434cb 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -2947,7 +2947,7 @@ BaseObjectPtr SQLTagStore::PrepareStatement( session->database_->connection_, sql.data(), sql.size(), &s, 0); if (r != SQLITE_OK) { - THROW_ERR_SQLITE_ERROR(isolate, "Failed to prepare statement"); + THROW_ERR_SQLITE_ERROR(isolate, session->database_.get()); sqlite3_finalize(s); return BaseObjectPtr(); } diff --git a/test/parallel/test-sqlite-template-tag.js b/test/parallel/test-sqlite-template-tag.js index 627de70392c1d8..f640e70f8c399a 100644 --- a/test/parallel/test-sqlite-template-tag.js +++ b/test/parallel/test-sqlite-template-tag.js @@ -102,3 +102,25 @@ test('TagStore capacity, size, and clear', () => { test('sql.db returns the associated DatabaseSync instance', () => { assert.strictEqual(sql.db, db); }); + +test('sql error messages are descriptive', () => { + assert.strictEqual(sql.run`INSERT INTO foo (text) VALUES (${'test'})`.changes, 1); + + // Test with non-existent column + assert.throws(() => { + const result = sql.get`SELECT nonexistent_column FROM foo`; + assert.fail(`Expected error, got: ${JSON.stringify(result)}`); + }, { + code: 'ERR_SQLITE_ERROR', + message: /no such column/i, + }); + + // Test with non-existent table + assert.throws(() => { + const result = sql.get`SELECT * FROM nonexistent_table`; + assert.fail(`Expected error, got: ${JSON.stringify(result)}`); + }, { + code: 'ERR_SQLITE_ERROR', + message: /no such table/i, + }); +});