Skip to content

fix: guard isFailure with nil check to simplify failure conditions#23

Merged
costela merged 3 commits into
mainfrom
fix/nil-error-guard-in-failure-condition
Mar 26, 2026
Merged

fix: guard isFailure with nil check to simplify failure conditions#23
costela merged 3 commits into
mainfrom
fix/nil-error-guard-in-failure-condition

Conversation

@costela
Copy link
Copy Markdown
Member

@costela costela commented Mar 26, 2026

Summary

  • Guard isFailure calls in hoglet.go with err != nil so that nil errors are always treated as successes without invoking the user-provided failure condition function
  • Simplify IgnoreContextCanceled and update WithFailureCondition docs to reflect the new contract
  • Minor Go style cleanups: rename sentinelerrSentinel, use any over interface{}, remove unnecessary loop variable copies (Go 1.22+)
  • Add regression test asserting that custom failure conditions are never called with a nil error

Test plan

  • Existing tests pass (go test ./...)
  • Verify that custom failure conditions no longer need to handle nil errors
  • Regression test confirms the nil-guard contract is enforced

🤖 Generated with Claude Code


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

… receive nil errors

Nil errors are now always treated as successes before calling the user-provided
failure condition function. This simplifies failure condition implementations
(e.g. IgnoreContextCanceled) by removing the need to handle the nil case.

Also applies minor Go style cleanups: rename sentinel → errSentinel, use `any`
instead of `interface{}`, and remove unnecessary loop variable copies (Go 1.22+).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Hoglet’s failure-observation behavior so that nil errors are always treated as successes and user-provided failure condition functions are only evaluated for non-nil errors, along with a few related doc/test cleanups.

Changes:

  • Guard isFailure(err) calls with err != nil when observing outcomes.
  • Update WithFailureCondition documentation and simplify IgnoreContextCanceled.
  • Minor test refactors (rename sentinel error var, use any, remove range-var copies in tests).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
options.go Updates failure-condition docs and simplifies IgnoreContextCanceled.
hoglet.go Ensures failure conditions aren’t invoked for nil errors by guarding observation.
hoglet_test.go Test cleanups (rename sentinel, any usage).
breaker_test.go Removes range-variable copies (safe given Go 1.24 toolchain).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hoglet.go
Comment thread options.go Outdated
Comment thread options.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

@costela I've opened a new pull request, #24, to work on those changes. Once the pull request is ready, I'll request review from you.

@costela costela requested a review from marcboeker March 26, 2026 11:35
@costela costela merged commit 3cb255f into main Mar 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants