Skip to content

fix(scripts): exit non-zero when Friendbot funding fails - #111

Merged
Busiii-adetiba merged 1 commit into
SynapsVault:mainfrom
Yuren0312:fix-fund-accounts-exit-code-31
Oct 18, 2026
Merged

Busiii-adetiba merged 1 commit into
SynapsVault:mainfrom
Yuren0312:fix-fund-accounts-exit-code-31

Conversation

@Yuren0312

Copy link
Copy Markdown
Contributor

Problem

scripts/02-fund-accounts.js (#31):

  • fund() called res.json() unconditionally. Friendbot answers some failures with HTML or plain text, so the step crashed with a SyntaxError instead of reporting the failure.
  • The script always exited 0, even when no account was funded, so a failed step 2 looked successful to anything chained after it.

Change

  • Read the body as text first and parse JSON from it (readBody), so a non-JSON error body is reported instead of crashing the step.
  • Validate every key with StrKey.isValidEd25519PublicKey before contacting Friendbot; invalid keys abort with exit 1 and Friendbot is never called.
  • Treat an already funded response as success — the account already holds testnet XLM.
  • Count failures and exit 1 when any account could not be funded; the "Next →" footer only prints on full success.
  • test/fund-accounts.test.cjs covers the exit-code contract end-to-end (the script is spawned with fetch stubbed by test/friendbot-fetch-stub.mjs): success, already-funded, non-JSON error body, network failure, partial failure, invalid keys and missing arguments.
  • README: document the new exit status for step 2.

Verification

  • The 7 new cases in test/fund-accounts.test.cjs pass (node --test, same command as npm test); they assert exit codes and captured output, and that Friendbot is never contacted for invalid keys.
  • node --check passes for every script.

Fixes #31

02-fund-accounts.js called res.json() unconditionally, so Friendbot's
HTML/text error bodies crashed the step with a SyntaxError, and the
script always exited 0 even when no account was funded.

- read the body as text first and parse JSON from it, so non-JSON
  error bodies are reported instead of crashing
- validate every key with StrKey.isValidEd25519PublicKey before
  contacting Friendbot
- treat an "already funded" response as success
- exit non-zero when any account could not be funded, so the step
  can be chained with &&
- cover the exit-code contract with node:test, stubbing fetch

Fixes SynapsVault#31
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.

02-fund-accounts.js exits 0 when funding fails and crashes on non-JSON responses

2 participants