Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Help text after failure should go to standard error

Open
#2,840 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
csharp
Domain
cli

Research direction

Reproduce the command shown in the issue and compare stdout and stderr when the required --ok option is omitted, including with 2>/dev/null. Done means validation-triggered help follows the error to stderr, while help explicitly requested with -h remains on stdout.

Written by the indexing model from the issue text.

Description

When emitting help text because a command's options weren't specified correctly, the help text should be printed to the standard error stream. This avoids mixing diagnostic messages with program output.

The error message is correctly written to stderr, but the help text is not and I think it should match the error message's behavior.

If help was explicitly asked for with -h, then it's probably okay to send that to standard output.

$ dotnet --version
10.0.301

$ cat ok.cs
#!/usr/bin/env dotnet
#:package [email protected]
using System.CommandLine;
var okOption = new Option<bool>("--ok")
{
    Description = "Required flag. When passed, the app prints \"ok\".",
    Required = true,
};
var rootCommand = new RootCommand("Prints \"ok\" when --ok is passed.")
{
    okOption,
};
rootCommand.Validators.Add(result =>
{
    if (result.GetResult(okOption) is null)
    {
        result.AddError($"Option '{okOption.Name}' is required.");
    }
});
rootCommand.SetAction(parseResult =>
{
    Console.WriteLine("ok");
    return 0;
});
return rootCommand.Parse(args).Invoke();

$ dotnet run ok.cs
Option '--ok' is required.

Description:
  Prints "ok" when --ok is passed.

Usage:
  ok [options]

Options:
  --ok (REQUIRED)  Required flag. When passed, the app prints "ok".
  -?, -h, --help   Show help and usage information
  --version        Show version information

But redirecting stderr to /dev/null shows that the help text (but not the error message) is printed to stdout:

$ dotnet run ok.cs 2> /dev/null
Description:
  Prints "ok" when --ok is passed.

Usage:
  ok [options]

Options:
  --ok (REQUIRED)  Required flag. When passed, the app prints "ok".
  -?, -h, --help   Show help and usage information
  --version        Show version information
Dominant language
C#
Stars
3.7k
Forks
432
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/command-line-api

All issues in dotnet/command-line-api

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.