Skip to content

fix(nip05): replace console.error with debug logger for fetch failures#395

Open
cardugarte wants to merge 1 commit into
nostr-dev-kit:masterfrom
cardugarte:fix/nip05-console-error
Open

fix(nip05): replace console.error with debug logger for fetch failures#395
cardugarte wants to merge 1 commit into
nostr-dev-kit:masterfrom
cardugarte:fix/nip05-console-error

Conversation

@cardugarte

Copy link
Copy Markdown

Problem

`src/user/nip05.ts` fires an unconditional `console.error` when a NIP-05 fetch fails:

```typescript
} catch (_e) {
ndk?.cacheAdapter?.saveNip05(fullname, null);
console.error("Failed to fetch NIP05 for", fullname, _e); // cannot be silenced
return null;
}
```

NIP-05 fetch failures are expected behavior — many Nostr users have unreachable or expired NIP-05 domains. Application developers have no way to opt out: the only workaround is monkey-patching `console.error`, which risks hiding real errors.

Closes #394

Fix

Add a `debug` instance scoped to `ndk:nip05` and replace the `console.error`:

```typescript
import debug from "debug";
const d = debug("ndk:nip05");

// in the catch block:
d("Failed to fetch NIP05 for %s: %O", fullname, _e);
```

Silent by default. Opt-in via `DEBUG=ndk:nip05`.

Why this is consistent

Every other NDK module already uses the `debug` package for internal logging (relay connectivity, subscriptions, authentication). The `nip05.ts` module was the only exception — this PR brings it in line with the rest of the codebase.

Changes

  • 1 new import (`debug`)
  • 1 new module-level constant (`const d = debug("ndk:nip05")`)
  • 1 line changed in the catch block

Zero behavior change. The function still returns `null` and saves a negative cache entry on failure.

NIP-05 fetch failures (unreachable domains, CORS, timeouts) are expected
behavior and cannot be silenced by application developers when using the
unconditional console.error. Every other NDK module uses the 'debug'
package which is silent by default and opt-in via DEBUG=ndk:nip05.

Fixes: nostr-dev-kit#394
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(nip05): replace unconditional console.error with debug logger in getNip05For

1 participant