Skip to content

Commit 1862449

Browse files
TypeErrors added.
1 parent 4b829ac commit 1862449

File tree

4 files changed

+86
-65
lines changed

4 files changed

+86
-65
lines changed

src/PuddySqlEngine.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class PuddySqlEngine {
5656
*/
5757
isConnectionError(err) {
5858
if (typeof err !== 'object' || err === null || Array.isArray(err))
59-
throw new Error('err must be a plain object');
59+
throw new TypeError('err must be a plain object');
6060
const sqlEngine = this.getSqlEngine();
6161
if (typeof sqlEngine === 'string') {
6262
// PostgreSQL

src/PuddySqlInstance.mjs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class PuddySqlInstance extends PuddySqlEngine {
8686
* @param {boolean} state - Set to `true` to enable colors, or `false` to disable.
8787
*/
8888
setConsoleColors(state) {
89-
if (typeof state !== 'boolean') throw new Error('state must be a boolean');
89+
if (typeof state !== 'boolean') throw new TypeError('state must be a boolean');
9090
this.#consoleColors = state;
9191
}
9292

@@ -108,7 +108,7 @@ class PuddySqlInstance extends PuddySqlEngine {
108108
*/
109109
#debugSql(value) {
110110
if (typeof value !== 'string' || value.trim() === '')
111-
throw new Error('value must be a non-empty string');
111+
throw new TypeError('value must be a non-empty string');
112112

113113
const useColor = this.#consoleColors !== false;
114114

@@ -362,9 +362,10 @@ class PuddySqlInstance extends PuddySqlEngine {
362362
*/
363363
#debugConsoleText(id, debugName = '', status = '') {
364364
if (typeof id !== 'string' && typeof id !== 'number')
365-
throw new Error('id must be a string or number');
366-
if (typeof debugName !== 'string') throw new Error('debugName must be a string if provided');
367-
if (typeof status !== 'string') throw new Error('status must be a string if provided');
365+
throw new TypeError('id must be a string or number');
366+
if (typeof debugName !== 'string')
367+
throw new TypeError('debugName must be a string if provided');
368+
if (typeof status !== 'string') throw new TypeError('status must be a string if provided');
368369
const useColor = this.#consoleColors !== false;
369370

370371
const reset = useColor ? '\x1b[0m' : '';
@@ -402,7 +403,7 @@ class PuddySqlInstance extends PuddySqlEngine {
402403
* @param {boolean} isDebug - If true, debug mode is enabled; otherwise, it's disabled.
403404
*/
404405
setIsDebug(isDebug) {
405-
if (typeof isDebug !== 'boolean') throw new Error('isDebug must be a boolean');
406+
if (typeof isDebug !== 'boolean') throw new TypeError('isDebug must be a boolean');
406407
this.#debug = isDebug;
407408
}
408409

@@ -432,8 +433,8 @@ class PuddySqlInstance extends PuddySqlEngine {
432433
* @throws {Error} If the table has already been initialized.
433434
*/
434435
async initTable(settings = {}, tableData = []) {
435-
if (!isJsonObject(settings)) throw new Error('settings must be a plain object');
436-
if (typeof settings.name !== 'string') throw new Error('settings.name must be a string');
436+
if (!isJsonObject(settings)) throw new TypeError('settings must be a plain object');
437+
if (typeof settings.name !== 'string') throw new TypeError('settings.name must be a string');
437438
if (!this.#tables[settings.name]) {
438439
const newTable = new PuddySqlQuery();
439440
newTable.setDb(settings, this);
@@ -456,7 +457,7 @@ class PuddySqlInstance extends PuddySqlEngine {
456457
*/
457458
getTable(tableName) {
458459
if (typeof tableName !== 'string' || tableName.trim() === '')
459-
throw new Error('tableName must be a non-empty string');
460+
throw new TypeError('tableName must be a non-empty string');
460461
const table = this.#tables[tableName];
461462
if (!table) throw new Error(`Table "${tableName}" does not exist`);
462463
return table;
@@ -486,7 +487,7 @@ class PuddySqlInstance extends PuddySqlEngine {
486487
*/
487488
removeTable(tableName) {
488489
if (typeof tableName !== 'string' || tableName.trim() === '')
489-
throw new Error('tableName must be a non-empty string');
490+
throw new TypeError('tableName must be a non-empty string');
490491
if (!this.#tables[tableName])
491492
throw new Error(`Table "${tableName}" does not exist and cannot be removed`);
492493
delete this.#tables[tableName];

0 commit comments

Comments
 (0)