Skip to content

feat: expose prog.error() for app-specific validation - #69

Open
Ultroncn wants to merge 1 commit into
lukeed:masterfrom
Ultroncn:feat/expose-error-utility
Open

Ultroncn wants to merge 1 commit into
lukeed:masterfrom
Ultroncn:feat/expose-error-utility

Conversation

@Ultroncn

@Ultroncn Ultroncn commented Nov 17, 2026 •

Copy link
Copy Markdown

Hi! This exposes the internal error utility as prog.error(message, code?), as requested in #54.

Why
Sade already prints a formatted ERROR block (with a Run \$ --help` for more info.` hint) for its own validation failures, but application-specific validations — e.g. two options conflicting with each other — had no way to reuse that same output. Now a CLI can do:

prog.action(args => {
  if (badCombo) prog.error('something is wrong');
});

and get the familiar output with exit code 1 by default (or a custom code via the second argument).

Change

  • src/index.js: new error(str, num) method delegating to the existing utils.error helper.
  • index.d.ts + readme.md: documented as prog.error(str).
  • deno/mod.js: same method added to the Deno port for parity.
  • Tests: test/index.js asserts the method exists; new fixture test/fixtures/error.js + a test in test/usage.js assert the exact stderr output and exit code 1.

Verification

  • Ran the repo's tape tests directly as native ESM (the old esm loader that npm test relies on no longer works on Node 24 — pre-existing and unrelated): test/index.js 141 pass, test/utils.js 27 pass, test/usage.js 430 pass, all ok.
  • Also verified against the rollup-built lib/: prog.error('something is wrong') prints the formatted error block and exits 1.

Happy to adjust the signature or docs if you'd prefer a different shape. Thanks!

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