Skip to content

internal/report claims it never exits, and it does #641

Description

@haribo

Why

internal/report's package comment, written when the package was split out in #491, says:

Nothing here writes to stdout or decides an exit code; it takes results and returns text,
which is what makes it testable.

report.go:192 calls os.Exit(1), inside JSON(), on a marshal failure.

The comment is mine, and so is the os.Exit. It was named in #585's description as "the
one piece of entanglement left in the package"
and deliberately left — then the package
comment was written claiming the opposite. A reader has no way to tell which is true
without grepping.

What to do

Two coherent options, and the choice matters more than the line:

  1. Make the comment true. JSON returns the marshal error, the caller decides. Its
    signature becomes (string, bool, error) — or the error folds into the bool with the
    message in the string, which is uglier but keeps the shape. Render and both call sites
    follow.
  2. Make the comment honest. Keep the exit, and say why: the failure is documented as
    impossible ("every field is a plain Go value"), and an empty report would be worse than a
    loud death.

Option 1 is the one that matches what the package is for. Option 2 is defensible only if
the exit is genuinely unreachable — in which case the honest form is a panic with a message,
not an exit, since an unreachable branch that exits looks like a decision.

Validation

  • Whichever way: grep -n "os.Exit" internal/report/ and the package comment agree.
  • The JSON report still ends with a newline and still redacts, which its tests cover.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: choreCI, tooling, maintenance

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions