Skip to content

Conversation

@bep
Copy link
Member

@bep bep commented Nov 24, 2025

No description provided.

Copy link

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 introduces error handling capabilities to the radix tree's walk functions by adding error return values to WalkFn, WalkHandler, and the public walk methods (Walk, WalkPrefix, WalkPath). This is a breaking API change that allows walk operations to propagate errors from user-provided handlers.

Key Changes:

  • Modified WalkFn and WalkHandler signatures to return errors in addition to their existing return values
  • Updated Walk, WalkPrefix, and WalkPath methods to return errors
  • Modified recursiveWalk internal function to propagate errors through the recursion stack
  • Updated all tests and benchmarks to comply with the new signatures

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 11 comments.

File Description
radix.go Core implementation changes: updated type signatures for WalkFn, WalkHandler, and walk methods to support error propagation; modified recursiveWalk to handle and return errors throughout the tree traversal
radix_test.go Comprehensive test updates: modified all walk function signatures to match new API, added TestWalkErrors to verify error propagation works correctly for Walk/WalkPrefix/WalkPath methods

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

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

return WalkContinue, zero
return WalkContinue, zero, nil
}
t.Walk(fn)
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The error returned by t.Walk(fn) is not being handled. Since Walk now returns an error, it should be checked and handled appropriately. Consider either returning the error from ToMap by changing its signature to func (t *Tree[T]) ToMap() (map[string]T, error), or silently ignoring it if errors are not expected here. Given that the walk function used here always returns nil, this might be acceptable, but the API design should be consistent.

Copilot uses AI. Check for mistakes.
var fn WalkFn[int] = func(s string, v int) (WalkFlag, int, error) {
return WalkContinue, v, nil
}
r.Walk(fn)
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The error returned by r.Walk(fn) is not being checked. Since Walk now returns an error, it should be checked in tests to ensure no unexpected errors occur. Consider using c.Assert(r.Walk(fn), qt.IsNil) or similar.

Suggested change
r.Walk(fn)
c.Assert(r.Walk(fn), qt.IsNil)
Copilot uses AI. Check for mistakes.
return WalkSet, v * 10, nil
},
}
r.Walk(h)
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The error returned by r.Walk(h) is not being checked. Since Walk now returns an error, it should be checked in tests to ensure no unexpected errors occur.

Copilot uses AI. Check for mistakes.
var fn WalkFn[int] = func(s string, v int) (WalkFlag, int, error) {
return WalkSet, v * 3, nil
}
r.Walk(fn)
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The error returned by r.Walk(fn) is not being checked. Since Walk now returns an error, it should be checked in tests to ensure no unexpected errors occur.

Suggested change
r.Walk(fn)
err := r.Walk(fn)
c.Assert(err, qt.IsNil)
Copilot uses AI. Check for mistakes.
return WalkContinue, ""
return WalkContinue, "", nil
}
r.WalkPrefix(test.inp, fn)
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The error returned by r.WalkPrefix(test.inp, fn) is not being checked. Since WalkPrefix now returns an error, it should be checked in tests to ensure no unexpected errors occur.

Suggested change
r.WalkPrefix(test.inp, fn)
err := r.WalkPrefix(test.inp, fn)
c.Assert(err, qt.IsNil)
Copilot uses AI. Check for mistakes.
return WalkSet, v * 10, nil
},
}
r.Walk(h)
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The error returned by r.Walk(h) is not being checked. Since Walk now returns an error, it should be checked in tests to ensure no unexpected errors occur.

Copilot uses AI. Check for mistakes.
return WalkSet, v * 10, nil
},
}
r.Walk(h)
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The error returned by r.Walk(h) is not being checked. Since Walk now returns an error, it should be checked in tests to ensure no unexpected errors occur.

Suggested change
r.Walk(h)
err := r.Walk(h)
c.Assert(err, qt.IsNil)
Copilot uses AI. Check for mistakes.
Comment on lines 200 to 201
r.Walk(fn)

Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The error returned by r.Walk(fn) is not being checked. Since Walk now returns an error, it should be checked in tests to ensure no unexpected errors occur.

Suggested change
r.Walk(fn)
err := r.Walk(fn)
c.Assert(err, qt.IsNil)
Copilot uses AI. Check for mistakes.
return WalkContinue, false
return WalkContinue, false, nil
}
r.Walk(fn)
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The error returned by r.Walk(fn) is not being checked. Since Walk now returns an error, it should be checked in tests to ensure no unexpected errors occur.

Suggested change
r.Walk(fn)
err := r.Walk(fn)
c.Assert(err, qt.IsNil)
Copilot uses AI. Check for mistakes.
return WalkContinue, ""
return WalkContinue, "", nil
}
r.WalkPath(test.inp, fn)
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The error returned by r.WalkPath(test.inp, fn) is not being checked. Since WalkPath now returns an error, it should be checked in tests to ensure no unexpected errors occur.

Suggested change
r.WalkPath(test.inp, fn)
err := r.WalkPath(test.inp, fn)
c.Assert(err, qt.IsNil)
Copilot uses AI. Check for mistakes.
@bep bep merged commit 6969ff1 into gohugoio:master Nov 24, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant