refactor: replace panics with returned errors#6
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces every production-code
panicin the since CLI with returned errors and gives the "no changes since tag" failure a friendly, actionable message.Summary
changelog,semver, andvcsnow return errors instead of panicking; every cobra subcommand usesRunEwithSilenceUsage/SilenceErrors.cmd/root.goprints failures as a singleError: ...line on stderr and exits non-zero — no more Go stack traces leaking to users.changelog.NoChangesErroris 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 newvcs.FilterStatscarries the considered/excluded counts up fromprocessCommits.ignore:regexes insince.yamlnow reportinvalid ignore pattern …instead of panicking viaregexp.MustCompile, and a repo with no tags returnsno 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
NoChangesErrorand 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".FetchCommitsByTaggains a third return value (FilterStats); existing callers that don't care discard it with_.processCommitsincrements theConsideredandExcludedcounters 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 rawgit logcount.