Skip to content

refactor: replace panics with returned errors#6

Merged
outofcoffee merged 2 commits into
mainfrom
refactor/replace-panics-with-errors
Jun 20, 2026
Merged

refactor: replace panics with returned errors#6
outofcoffee merged 2 commits into
mainfrom
refactor/replace-panics-with-errors

Conversation

@outofcoffee

Copy link
Copy Markdown
Collaborator

Replaces every production-code panic in the since CLI with returned errors and gives the "no changes since tag" failure a friendly, actionable message.

Summary

  • Library helpers in changelog, semver, and vcs now return errors instead of panicking; every cobra subcommand uses RunE with SilenceUsage / SilenceErrors.
  • cmd/root.go prints failures as a single Error: ... line on stderr and exits non-zero — no more Go stack traces leaking to users.
  • New changelog.NoChangesError is returned when nothing remains after filtering, e.g. no eligible commits since v1.17.4 — 1 commit(s) were excluded by ignore patterns in since.yaml. A new vcs.FilterStats carries the considered/excluded counts up from processCommits.
  • Tightens latent crashes: invalid ignore: regexes in since.yaml now report invalid ignore pattern … instead of panicking via regexp.MustCompile, and a repo with no tags returns no tags found in repository … instead of dereferencing a nil tag reference.

Implementation details

The refactor was split into two commits: the mechanical panic-removal pass, then the UX layer that introduces NoChangesError and the filter-stats plumbing. Keeping them apart makes the second commit easy to review on its own — it is the only part that changes behaviour beyond "no more stack traces".

FetchCommitsByTag gains a third return value (FilterStats); existing callers that don't care discard it with _. processCommits increments the Considered and Excluded counters only for non-tag commits past the skip window, so the counts reflect what the user actually intends to see in the changelog rather than the raw git log count.

Library helpers in changelog, semver and vcs now propagate errors
instead of panicking, and every cobra subcommand has been switched
from Run+panic to RunE+return. cmd/root.go prints errors as a single
"Error: ..." line and exits non-zero, so failures no longer dump a Go
stack trace at the user. Also tightens a few latent crashes: invalid
ignore-pattern regexes and repositories with no tags now report a
clean error instead of panicking via MustCompile / a nil dereference.
Threads a FilterStats counter through processCommits so we know how
many commits were eligible vs how many got dropped by since.yaml
ignore patterns. When the changelog generator finds nothing to emit
it now returns a NoChangesError that points the user at the most
likely cause — e.g. "no eligible commits since v1.17.4 — 1 commit(s)
were excluded by ignore patterns in since.yaml" — rather than the
opaque "no changes since start tag" that previously panicked the CLI.
@outofcoffee outofcoffee added the enhancement New feature or request label Jun 16, 2026
@outofcoffee outofcoffee merged commit 1f074fa into main Jun 20, 2026
1 check passed
@outofcoffee outofcoffee deleted the refactor/replace-panics-with-errors branch June 20, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant