errorcounter: Allow provision of custom error counter#159
Conversation
WalkthroughThis pull request promotes the error counter to the public API by adding an Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)builder_internal_test.go (3)
🔇 Additional comments (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
errors.go (1)
13-18: Clarify ErrorCounter’s contract (concurrency + return semantics)Now that
ErrorCounteris part of the public API, it would help implementers if the doc comment explicitly stated that:
- Implementations are expected to be safe for concurrent use by multiple goroutines.
Addreturns the updated count for the(err, labels...)combination.Countreturns the current count.Clearresets the count (and whether it is acceptable to be a no-op if the key doesn’t exist).This keeps custom implementations aligned with how the built-in counter is used throughout the workflow runtime.
internal/errorcounter/errorcounter.go (1)
8-12: Keep Counter as-is, but consider centralising key constructionThe move to a concrete
*Counterwith mutex-protectedAdd/Count/Clearpreserves existing behaviour and concurrency-safety.As a small internal clean-up, you could factor out the repeated
errMsgconstruction into a private helper (e.g.key(err error, labels ...string) string) so any future change to key format is made in one place only.Also applies to: 14-17, 19-45
builder.go (1)
25-42: ErrorCounter wiring via builder is correct; consider softening the doc commentThe end-to-end wiring looks solid:
NewBuildersets a sensible default viaerrorcounter.New().buildOptions.errorCounterplusWithErrorCountergive a straightforward DI hook.Buildonly overridesworkflow.errorCounterwhen a custom value is provided, so the default stays in place otherwise.- Tests exercise both the custom and default paths.
One minor polish point: the
WithErrorCountercomment currently references the internal package (errorcounter.New()). Since that package isn’t importable by external users, you might rephrase this to something like “The default is an in‑memory error counter created byNewBuilder.” to avoid exposing internal details in the public API docs.Also applies to: 248-250, 269-278, 333-338
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
builder.go(3 hunks)builder_internal_test.go(5 hunks)errors.go(1 hunks)internal/errorcounter/errorcounter.go(3 hunks)pause.go(1 hunks)step.go(1 hunks)workflow.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
step.go (1)
errors.go (1)
ErrorCounter(14-18)
workflow.go (1)
errors.go (1)
ErrorCounter(14-18)
builder_internal_test.go (2)
internal/errorcounter/errorcounter.go (1)
New(8-12)builder.go (2)
WithErrorCounter(334-338)NewBuilder(25-43)
builder.go (1)
errors.go (1)
ErrorCounter(14-18)
pause.go (1)
errors.go (1)
ErrorCounter(14-18)
🔇 Additional comments (4)
workflow.go (1)
95-102: Decoupling Workflow from internal errorcounter looks goodSwitching
errorCounterto the publicErrorCounterinterface cleanly removes the dependency on the internal package and aligns withWithErrorCounter/NewBuilderwiring. No behavioural issues spotted here.pause.go (1)
13-21: maybePause correctly switched to the public ErrorCounterUpdating the
counterparameter toErrorCountercleanly hooks the injected/custom counter into the pause logic without altering behaviour. Call sites and usage (Add/Clear) remain consistent.step.go (1)
65-101: ErrorCounter injection into stepConsumer is consistentPassing
w.errorCounterintostepConsumerand changing the parameter type toErrorCountercleanly wires the configurable counter through to the step logic. The integration withmaybePauseis consistent and doesn’t alter existing behaviour.Also applies to: 103-114
builder_internal_test.go (1)
18-21: Tests give good coverage of custom/default error counter wiringThe added assertions in
TestBuildOptionsplus the newTestWithErrorCounterandTestDefaultErrorCounternicely verify:
- A provided counter is plumbed through as‑is.
- A default, non‑nil counter exists when none is supplied.
This should catch regressions in the builder wiring around
ErrorCounter.Also applies to: 115-170, 569-585
|
|
Note Docstrings generation - SUCCESS |
…counter` Docstrings generation was requested by @andrewwormald. * #159 (comment) The following files were modified: * `builder.go` * `internal/errorcounter/errorcounter.go` * `pause.go` * `step.go`
…counter` (#160) Docstrings generation was requested by @andrewwormald. * #159 (comment) The following files were modified: * `builder.go` * `internal/errorcounter/errorcounter.go` * `pause.go` * `step.go` Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

Issue: #156
Allows the provision of a custom error counter as a build option.