Skip to content

Replace the literal <cmd> placeholder in usage-error hints #5196

Description

@Widthdom

Summary

Suggestions usage errors expose the internal literal placeholder <cmd> instead of an executable help command. The defect appears in both human and structured JSON errors.

Environment

  • origin/main: c642bc4c3dda4ef659df8e6b699e10f61da3c836
  • cdidx v1.44.3, locally built
  • full net8.0 and net9.0 suites pass

Reproduction

Human output:

dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll suggestions list \
  --bogus --db .cdidx/codeindex.db
Error: --bogus is not supported for suggestions.
Hint: Run '<cmd> --help' for usage information.

Structured output:

dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll suggestions show \
  --db .cdidx/codeindex.db --json
{
  "message": "suggestions show requires an id.",
  "hint": "Run '<cmd> --help' for usage information."
}

The same placeholder also appears in option-compatibility errors such as using --actor outside suggestions update.

Expected behavior

Use the nearest executable help surface, for example:

Run `cdidx suggestions --help` for usage information.

If command identity is unavailable, fall back truthfully to cdidx --help.

Root cause

  • src/CodeIndex/Cli/CommandErrorWriter.cs:9 defines DefaultHint as the final literal Run '<cmd> --help' for usage information.
  • Suggestions preflight and usage paths pass that constant directly.
  • Some error-writer paths already know the canonical command, but the default-hint API does not consume it.

Focused PR scope

One PR should:

  1. replace the literal constant with a command-aware hint builder;
  2. pass canonical command identity from suggestions usage/preflight paths;
  3. provide a safe global fallback;
  4. keep human and JSON hints equivalent;
  5. audit current callers for the same placeholder exposure;
  6. add a bilingual changelog fragment.

Non-goals

  • Do not redesign all CLI diagnostics.
  • Do not infer commands from arbitrary error text.
  • Do not expand this into help-content generation.

Implementation guidance and cautions

  • Accept a canonical bounded command identifier, not untrusted free text.
  • Use existing diagnostic quoting/formatting helpers.
  • Do not perform a global post-serialization replacement.
  • Preserve error codes, exit codes, categories, and usage blocks.
  • Prefer the nearest actually supported help surface for nested commands.

Required tests

  • Suggestions unknown option in human mode.
  • Missing suggestions ID and invalid option combinations in JSON mode.
  • Known-command and unknown-command fallback paths.
  • Assert no user-facing output contains literal <cmd>.
  • Preserve existing error/usage contracts.

Acceptance criteria

  • No user-facing error emits <cmd>.
  • Suggestions errors point to an executable help command.
  • Human and JSON paths agree.
  • Existing structured error contracts do not regress.

Duplicate preflight

No exact open or closed issue was found for the literal default-hint placeholder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .NET codebugSomething isn't workinggood first issueGood for newcomerstests

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions