Skip to content

cli: name the accepted range in Invalid port and fold the port parsers' checks - #1075

Merged
blove merged 1 commit into
mainfrom
blove/port-parser-polish
Oct 22, 2026
Merged

blove merged 1 commit into
mainfrom
blove/port-parser-polish

Conversation

@blove

@blove blove commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Follow-up polish to #1062, from the maintainer review of the software factory's #1050. No change to which values are accepted; only the error text and the shape of the checks change.

Changes

  • One condition per parser. packages/cli/src/lib/dev/parse-port.ts and packages/cli/src/commands/start.ts each folded the digits-only test and the range test into a single if. After /^\d+$/, Number() can only yield a non-negative integer or Infinity (which fails > 65535), so the separate Number.isInteger guard was redundant.

  • The error names the accepted range.

    • b4 dev / b4 inspect: Invalid port: 70000 (expected an integer from 1 to 65535)
    • b4 start: Invalid port: 70000 (expected an integer from 0 to 65535), since it accepts 0 for a kernel-assigned port.

    The exit code stays 2.

  • Stale comment fixed. start.ts referred to "dev.ts's parsePort"; the shared parser lives in lib/dev/parse-port.ts and serves b4 dev and b4 inspect.

  • Tests. port-parse.test.ts and start-command.test.ts assert the new messages, and parsePort("0") is now covered.

  • Changeset. .changeset/port-parser-range-message.md, @b4run/cli patch.

Out of scope: resolveServePort in serve-runtime.ts (the PORT env var, #1066) silently falls back to 8000 instead of throwing. That is a deliberate, separate contract.

Verification (local, at the repo root)

  • pnpm lint, pnpm build, and pnpm --filter @b4run/cli typecheck: pass
  • pnpm --filter @b4run/cli test: 2879 passed, 4 skipped, 0 failed
  • node scripts/check-changesets.mjs: passed

🤖 Generated with Claude Code

…ers' checks

Follow-up polish to #1062 from the review of #1050:

- Fold the digits-only check and the range check into one condition in both
  parsers. After `/^\d+$/`, Number() can only return a non-negative integer or
  Infinity, so the separate `Number.isInteger` guard was redundant.
- An invalid `--port` now says what is accepted: `1 to 65535` for b4 dev and
  b4 inspect, `0 to 65535` for b4 start.
- Fix the stale "dev.ts's parsePort" comment in start.ts; the shared parser
  lives in lib/dev/parse-port.ts.
- Update the message assertions and cover `parsePort("0")`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
b4-run Ready Ready Preview Oct 22, 2026 4:07pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
navlog-web Ignored Ignored Preview Oct 22, 2026 4:07pm UTC

Request Review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated approval for repository bookkeeping. The maintainer reviews and merges this PR.

@blove
blove temporarily deployed to vercel-preview October 22, 2026 16:05 — with GitHub Actions Inactive
@blove
blove merged commit af302f0 into main Oct 22, 2026
31 checks passed
@blove
blove deleted the blove/port-parser-polish branch October 22, 2026 16:12

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – b4-run — f0e825ca Deployed Oct 22, 2026 by vercel[bot]
vercel-preview — f0e825ca Deployed Oct 22, 2026 by blove via vercel-native #3139
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.

1 participant