Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: slices: return the error instead of causing panic #63187

Closed
massongit opened this issue Sep 24, 2023 · 3 comments
Closed

proposal: slices: return the error instead of causing panic #63187

massongit opened this issue Sep 24, 2023 · 3 comments
Labels
Milestone

Comments

@massongit
Copy link

slices.Min, slices.MinFunc, slices.Max and slices.MaxFunc cause a panic if the given slice is empty.
However, if a panic causes, the execution side will not be able to properly handle the error.
Therefore, I want these functions to also return a error as a return value.

@gopherbot
Copy link

Change https://go.dev/cl/530677 mentions this issue: slices: return the error

@AlexanderYastrebov
Copy link
Contributor

Panic mode is documented and caller code that does not check that slice is empty is not following function contract.
With your proposal caller would have to check error result so it does not reduce code complexity, just moves the check to later phase.
IMO given that these functions are already deployed it is unlikely this change would be accepted.

@seankhliao
Copy link
Member

closing as infeasible.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants