Skip to content

refactor(uffd): extract safeInvoke helper#2442

Merged
ValentaTomas merged 2 commits intomainfrom
refactor/uffd-extract-safe-invoke
Apr 18, 2026
Merged

refactor(uffd): extract safeInvoke helper#2442
ValentaTomas merged 2 commits intomainfrom
refactor/uffd-extract-safe-invoke

Conversation

@ValentaTomas
Copy link
Copy Markdown
Member

Summary

  • Introduce a small `safeInvoke(fn)` helper in a new `invoke.go` that calls `fn` and returns its result, or `nil` if `fn` is nil.
  • Use it in `faultPage`'s two failure paths, replacing the duplicated `if onFailure != nil { signalErr = onFailure() }` blocks.

Pure refactor, no behavior change.

Split out of #2419 alongside #2441 (Prefault extraction).

Test plan

  • `go build ./...` passes
  • `go vet ./pkg/sandbox/uffd/...` clean
  • `golangci-lint run ./pkg/sandbox/uffd/...` clean

Introduce a small safeInvoke(fn) helper in a dedicated invoke.go and
use it in faultPage's two failure paths, replacing duplicated
`if onFailure != nil { signalErr = onFailure() }` blocks.

Pure refactor, no behavior change.
@cursor
Copy link
Copy Markdown

cursor bot commented Apr 18, 2026

PR Summary

Low Risk
Low risk refactor: centralizes nil-checking around the optional onFailure callback without changing error paths or retry/copy behavior. Risk is limited to inadvertent differences in when/if the callback is invoked, but the new helper preserves the prior logic (nil => no-op).

Overview
Extracts a small safeInvoke(func() error) helper and uses it in faultPage failure handling to remove duplicated onFailure nil-check/invocation logic when joining and reporting errors.

Reviewed by Cursor Bugbot for commit cf2b55e. Bugbot is set up for automated code reviews on this repo. Configure here.

@ValentaTomas ValentaTomas enabled auto-merge (squash) April 18, 2026 07:52
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

LGTM — straightforward deduplication with no behavior change.

Extended reasoning...

Overview

Adds a 3-line safeInvoke helper in a new invoke.go and replaces the two identical inline nil-check blocks in faultPage with calls to it. Only two files changed.

Security risks

None. The helper is internal to the package, touches only the error-path callback invocation, and introduces no new inputs or trust boundaries.

Level of scrutiny

Minimal scrutiny needed. This is a mechanical deduplication with provably identical semantics: safeInvoke(fn) returns nil when fn == nil and fn() otherwise, which is exactly what the replaced inline blocks did.

Other factors

No bugs reported, author verified go build, go vet, and golangci-lint all pass. The change is small, self-contained, and easy to audit by inspection.

@ValentaTomas ValentaTomas merged commit f2d9238 into main Apr 18, 2026
45 checks passed
@ValentaTomas ValentaTomas deleted the refactor/uffd-extract-safe-invoke branch April 18, 2026 19:07
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.

2 participants