Skip to content

fix: wallet list writes only JSON to stdout (#154) - #584

Open
ygd58 wants to merge 2 commits into
nansen-ai:mainfrom
ygd58:fix/wallet-list-stdout-json
Open

fix: wallet list writes only JSON to stdout (#154)#584
ygd58 wants to merge 2 commits into
nansen-ai:mainfrom
ygd58:fix/wallet-list-stdout-json

Conversation

@ygd58

@ygd58 ygd58 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #154.

Problem

nansen wallet list wrote its human-readable summary directly to stdout via console.log and returned undefined, so the CLI's normal {success, data} JSON envelope was never emitted. nansen wallet list | jq . had nothing valid to parse — breaking scripting/agent use, which this CLI is explicitly built for.

Fix

  • The list handler now returns the listWallets() result instead of undefined, so the existing CLI dispatcher wraps it in the standard {"success":true,"data":{...}} envelope and prints it to stdout — consistent with every other command.
  • The human-readable summary (and the "No wallets found" message) now goes to stderr via the errorOutput dep, so a human running it interactively still gets the friendly view, but stdout stays clean JSON.
  • As a side effect, --pretty, --table, and --csv now work on wallet list too, since they're handled generically by formatOutput once the command returns data instead of short-circuiting.
  • Updated the existing Privy-provider test to assert against errorOutput instead of log, and added two new tests covering the stdout/stderr split for both the populated and empty-wallet cases.

Testing

npm test
Test Files  1 failed | 65 passed (66)
     Tests  5 failed | 2675 passed | 16 skipped (2696)

The 5 failures are all pre-existing, in src/__tests__/doctor.test.js, and reproduce identically on main without this change — they rely on chmod-based unreadable-file simulation, which doesn't apply when tests run as root. Unrelated to this fix.

npm run lint

Clean, no output.

Manual verification:

$ nansen wallet list | jq .
{
  "success": true,
  "data": { "wallets": [...], "defaultWallet": "..." }
}

Human-readable summary confirmed on stderr, not stdout.

Checklist

  • npm test passes (output above; unrelated pre-existing failures noted)
  • npm run lint passes
  • New code paths have tests
  • No console.log in core (uses injected log/errorOutput deps)
  • Changeset added (patch — bug fix, user-facing output behavior change)
  • src/schema.json — no changes needed (no new commands/options)

@nansen-pr-reviewer

nansen-pr-reviewer Bot commented Sep 4, 2026

Copy link
Copy Markdown

pr-reviewer Summary for #0b7b1b9

No issues found

The code review completed successfully with no findings.

Review effort: 2/5 (Simple)

Summary

This is a clean, well-scoped bug fix. The core change — having wallet list return listWallets() instead of undefined, and routing the human-readable summary to errorOutput — is exactly the right approach and is consistent with how the rest of the dispatcher works. The fix is minimal, the tests cover both the happy path and the empty-wallet edge case, and the changeset and AGENTS.md are correctly updated.

A few things I verified and found to be fine:

  • Dispatcher wiring (cli.js lines 2086–2127): the result === undefined short-circuit fires for operational commands that return nothing; for wallet list the non-undefined return falls through to the formatOutput / JSON envelope path as intended. --pretty, --table, and --csv will now work correctly on this command.
  • Test isolation: beforeEach creates a fresh tempDir and stubs HOME, afterEach cleans up. The second new test (no-wallets case) correctly relies on the empty temp dir produced by beforeEach, not on any shared state.
  • errorOutput default: falls back to console.error, which is the correct stream for interactive human output and correctly avoids contaminating stdout.
  • Changeset: patch semver is appropriate for a bug fix; package name "nansen-cli" matches package.json.
  • AGENTS.md update: the exception to the "operational commands return undefined" rule is now correctly documented with the rationale and issue reference.

No actionable findings.


Token usage: 4,932 input, 4,362 output, 531,346 cache read, 35,344 cache write | Usage Guide

New pushes are reviewed automatically with a 10-minute cooldown between reviews. To request a review at any time, comment @nansen-pr-reviewer re-review.

nansen-pr-reviewer[bot]
nansen-pr-reviewer Bot previously approved these changes Sep 4, 2026

@nansen-pr-reviewer nansen-pr-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approved

This PR was automatically approved because:

  • Claude recommends approval
  • Claude assessed this as a moderate effort change
  • The effort level is within the auto-approval threshold of 2
  • No high or critical issues were detected
  • Review comment contains non-blocking feedback

If you have any concerns, please request a manual review.

@nansen-pr-reviewer nansen-pr-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approved

This PR was automatically approved because:

  • Claude recommends approval
  • Claude assessed this as a moderate effort change
  • The effort level is within the auto-approval threshold of 2
  • No high or critical issues were detected

If you have any concerns, please request a manual review.

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.

🟡 [Medium] wallet list writes human-readable text + JSON to stdout simultaneously (breaks piping)

1 participant