Repository navigation
refactor: use errors.As/Is for idiomatic error checks - #363
Open
tenthirtyam wants to merge 2 commits into
Open
tenthirtyam wants to merge 2 commits into
tenthirtyam wants to merge 2 commits into
Conversation
tenthirtyam
force-pushed
the
refactor/idiomatic-error-checks
branch
from
September 9, 2026 19:50
c7a38b8 to
5b4a90b
Compare
Replace direct type assertions and equality checks with `errors.As` and `errors.Is` to properly handle wrapped errors. Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
tenthirtyam
force-pushed
the
refactor/idiomatic-error-checks
branch
from
November 12, 2026 00:34
5b4a90b to
5dea77f
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Typed-nil *MultiError values are incorrectly retained instead of treated as empty or ignored, producing spurious <nil> entries and inflated validation error counts.
2 open issues
What changed in this PR
This PR updates error checks across configuration decoding, SSH communication, filesystem syncing, and error aggregation to recognize wrapped errors using errors.As and errors.Is.
Changes:
- Replace direct error type assertions with
errors.As. - Replace sentinel error comparisons with
errors.Is, including the SSH handshake timeout test. - Refactor
MultiErrorAppendto identify nested multi-errors.
| File | Description |
|---|---|
template/config/decode.go |
Recognize wrapped cty.PathError values during decoding. |
sdk-internals/communicator/ssh/communicator.go |
Recognize wrapped SSH exit errors. |
sdk-internals/communicator/ssh/communicator_test.go |
Use errors.Is for handshake timeout checks. |
packer/multi_error.go |
Use errors.As when accumulating multi-errors. |
cmd/packer-sdc/internal/fs/sync.go |
Recognize wrapped link and Windows privilege errors. |
Review effort: Balanced
A nil MultiError was counted as a real error, so the first validation failure showed up twice and one entry was "<nil>". Treat that nil as empty again. Signed-off-by: Ryan Johnson <ryan@tenththirtyam.org>
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.

Description
Replace direct type assertions and equality checks with
errors.Asanderrors.Isto properly handle wrapped errors.Rollback Plan
Revert commit.
Changes to Security Controls
None