Skip to content

Return errors from must list helpers for invalid inputs - #500

Open
ViktorBystrov72 wants to merge 1 commit into
Masterminds:masterfrom
ViktorBystrov72:fix-list-helper-errors
Open

ViktorBystrov72 wants to merge 1 commit into
Masterminds:masterfrom
ViktorBystrov72:fix-list-helper-errors

Conversation

@ViktorBystrov72

Copy link
Copy Markdown

The must list helpers are documented to return errors, but nil inputs currently panic in reflect.TypeOf(...).Kind(). mustChunk also panics or silently accepts nonpositive sizes, and mustSlice panics on invalid bounds and on ordinary arrays passed through an interface.

Validate these inputs before reflection or allocation, return the existing type errors for nil values, and make arrays addressable before slicing. Chunk counts use integer arithmetic. Valid slice reslicing up to capacity and existing empty-list results are preserved; the non-must wrappers still panic when their helper returns an error.

Regression coverage includes all twelve affected nil-input helpers, zero/negative chunk sizes on empty and populated lists, invalid slice bounds, array slicing, and a valid capacity-based reslice. Thirty-two assertions fail on the base implementation and pass with the fix.

Validation on macOS arm64:

  • Go 1.23.0: TZ=UTC go test -race -cover -count=1 ./... passes, with 85.7% coverage.
  • Go 1.27.3: TZ=UTC go test -race -cover -skip '^TestRound$' -count=1 ./... passes; go vet ./..., go build ./..., gofmt, and git diff --check also pass.
  • The unmodified base fails TestHtmlDate in the machine's local timezone and TestRound under Go 1.27.3 on arm64. UTC addresses the date test's existing timezone assumption; the rounding failure also reproduces on the base and is covered by the existing PR Prevent fused arithmetic from changing round results #488.

Signed-off-by: Виктор Быстров <anatema@bk.ru>

This branch has not been deployed

No deployments
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.

1 participant