Skip to content

Add test coverage for nil Len() behavior#142

Open
veeceey wants to merge 1 commit intohashicorp:mainfrom
veeceey:fix/issue-54-nil-len-panic
Open

Add test coverage for nil Len() behavior#142
veeceey wants to merge 1 commit intohashicorp:mainfrom
veeceey:fix/issue-54-nil-len-panic

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 13, 2026

Summary

The nil check in Len() was added in PR #95 but didn't include test coverage. This PR adds TestLenNil to verify that calling Len() on a nil *Error returns 0 instead of panicking.

Test Results

$ go test ./... -v
...
=== RUN   TestLenNil
--- PASS: TestLenNil (0.00s)
PASS
ok      github.com/hashicorp/go-multierror      0.243s

Verified manually that nil and empty multierror both return 0:

var merr *multierror.Error
fmt.Printf("Len of nil multierror: %d\n", merr.Len())  // Output: 0

merr = &multierror.Error{}
fmt.Printf("Len of empty multierror: %d\n", merr.Len())  // Output: 0

Fixes #54

The nil check in Len() was added in PR hashicorp#95 but lacked test coverage.
This adds TestLenNil to verify that calling Len() on a nil *Error
returns 0 instead of panicking.

Fixes hashicorp#54
@veeceey veeceey requested a review from a team as a code owner February 13, 2026 08:48
@ritikrajdev
Copy link

Hey @veeceey , Thanks for the contribution. This test case looks good to me but can you please resolve the failing lint CI !

@veeceey
Copy link
Author

veeceey commented Feb 16, 2026

Thanks for the review, @ritikrajdev! I looked into the lint failure and it's not related to my changes — the lint job uses golangci-lint-action without pinning a version, so it pulled golangci-lint v2.9.0 (latest), which passes the -buildvcs flag to go list. That flag was introduced in Go 1.18, but the repo's go.mod specifies Go 1.13, which is what the lint job uses via go-version-file: go.mod.

The lint job last passed on main on Jan 30 when an older golangci-lint version was in use. Since then, the latest version has moved to v2.9.0 and any new PR branch will hit this same failure. This is a pre-existing CI configuration issue — not caused by the test I added.

All actual test jobs (linux and windows across Go 1.13, oldstable, and stable) pass.

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.

Len() with nil multierror should return 0 instead of panic

2 participants