From 926f6c7d39f4ad515feec43ac09903f43c714a6e Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 16 Jun 2025 06:33:46 -0700 Subject: [PATCH] Fix config silently failing due to type assertion if no options object is passed. --- src/lib/config/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/config/index.ts b/src/lib/config/index.ts index 7575d1c..5eb7667 100644 --- a/src/lib/config/index.ts +++ b/src/lib/config/index.ts @@ -54,7 +54,7 @@ class NanoPowConfigConstructor implements NanoPowOptions { // Assign API if valid value passed static async #getValidApi (input: Record): Promise { - if (input.api != null) { + if (input != null && input.api != null) { if (typeof input.api === 'string') { try { input.api = input.api.toLowerCase() @@ -79,7 +79,7 @@ class NanoPowConfigConstructor implements NanoPowOptions { // Assign debug if valid value passed static #getValidDebug (input: Record): boolean { - if (input.debug != null) { + if (input != null && input.debug != null) { if (typeof input.debug === 'bigint' || typeof input.debug === 'number') { input.debug = input.debug.toString() } @@ -96,7 +96,7 @@ class NanoPowConfigConstructor implements NanoPowOptions { // Assign difficulty if valid value passed static #getValidDifficulty (input: Record): bigint { - if (input.difficulty != null) { + if (input != null && input.difficulty != null) { if (typeof input.difficulty === 'string') { try { input.difficulty = bigintFrom(input.difficulty, 'hex') @@ -115,7 +115,7 @@ class NanoPowConfigConstructor implements NanoPowOptions { // Assign effort if valid value passed static #getValidEffort (input: Record): number { - if (input.effort != null) { + if (input != null && input.effort != null) { if (typeof input.effort !== 'number') { throw new Error(`Invalid effort (${typeof input.effort})${input.effort}`) } -- 2.47.3