Skip to content

fix(cli): write error message to stderr before showing help#34604

Open
Robin1987China wants to merge 1 commit into
anomalyco:devfrom
Robin1987China:fix-cli-fail-error
Open

fix(cli): write error message to stderr before showing help#34604
Robin1987China wants to merge 1 commit into
anomalyco:devfrom
Robin1987China:fix-cli-fail-error

Conversation

@Robin1987China

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #29390

Type of change

  • Bug fix

What does this PR do?

When the user passes an unknown argument or invalid value, the .fail() handler calls cli.showHelp() but never writes the error message to stderr. This makes opencode --unknown-flag silently show help output identical to opencode --help, leaving the user unaware of the error.

This adds process.stderr.write(msg + "\n") before showing help so the user sees what went wrong.

How did you verify your code works?

  • Typecheck: bun run typecheck passes cleanly (full monorepo 29/29)
  • Manual verification: error conditions remain unchanged, msg is now written to stderr

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When the user passes an unknown argument or invalid value, the .fail()
handler calls cli.showHelp() but never writes the error message to
stderr.  This makes opencode --unkown-flag silently show help output
identical to opencode --help, leaving the user unaware of the error.

Closes anomalyco#29390
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found several related PRs that address similar CLI error handling issues:

  1. PR fix(opencode): show CLI failure message before help #31228 - fix(opencode): show CLI failure message before help

    • Directly related: appears to address the same issue of showing failure messages before help
  2. PR fix(opencode): output error message before help in .fail() handler #31488 - fix(opencode): output error message before help in .fail() handler

    • Directly related: specifically targets the .fail() handler to output error messages before help
  3. PR fix(opencode): add trailing newline to help output #30547 - fix(opencode): add trailing newline to help output

    • Somewhat related: deals with help output formatting

These PRs (especially #31228 and #31488) appear to be addressing the exact same problem as PR #34604 - ensuring error messages are displayed before help output when the user provides invalid arguments. You may want to verify whether these earlier PRs were closed without merging or if there's a reason they need to be revisited with this new approach.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(opencode): CLI .fail() handler swallows error message

1 participant