Skip to content

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

Description

@cardugarte

Problem

src/user/nip05.ts uses a hardcoded console.error when a NIP-05 fetch fails:

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

This fires unconditionally on any network failure — unreachable domain, CORS error, timeout — and cannot be silenced without monkey-patching console.error. NIP-05 fetch failures are expected behavior (many Nostr users have unreachable or expired NIP-05 domains), so logging them as errors inflates console noise and confuses application developers who have no way to opt out.

Expected behavior

The rest of NDK uses the debug package consistently (e.g. relay connectivity, subscriptions, authentication). The nip05.ts module is the only place that breaks this pattern with a bare console.error.

Proposed fix

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

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

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

This makes the log silent by default and opt-in via DEBUG=ndk:nip05 — consistent with how every other NDK module handles internal errors.

Impact

  • Zero behavior change: the function still returns null and saves a negative cache entry.
  • Developers can enable DEBUG=ndk:nip05 when they need to trace NIP-05 resolution issues.
  • Eliminates unavoidable console noise in applications that verify NIP-05 identifiers at scale (e.g. badge grids, feed profiles).

NDK version

Reproduced on @nostr-dev-kit/ndk@3.0.3.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions