Skip to content

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

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

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

@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.

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.
Closesanomalyco#29390
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for freeto 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

@Robin1987China