fix(nip05): replace console.error with debug logger for fetch failures#395
Open
cardugarte wants to merge 1 commit into
Open
fix(nip05): replace console.error with debug logger for fetch failures#395cardugarte wants to merge 1 commit into
cardugarte wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Zero behavior change. The function still returns `null` and saves a negative cache entry on failure.