]> git.codecow.com Git - nano-pow.git/commitdiff
Fix config silently failing due to type assertion if no options object is passed.
authorChris Duncan <chris@zoso.dev>
Mon, 16 Jun 2025 13:33:46 +0000 (06:33 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 16 Jun 2025 13:33:46 +0000 (06:33 -0700)
src/lib/config/index.ts

index 7575d1c3b57f94e33f87fdbb2388bc0cf40bb056..5eb766723db4831d1d36c8d577a8684407584fea 100644 (file)
@@ -54,7 +54,7 @@ class NanoPowConfigConstructor implements NanoPowOptions {
 
        // Assign API if valid value passed
        static async #getValidApi (input: Record<string, unknown>): Promise<ApiSupportedTypes> {
-               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<string, unknown>): 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<string, unknown>): 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<string, unknown>): 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}`)
                        }