-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
After throws unhelpful error message on passing invalid index #6415
Comments
I agree that the error isn't great. Another problem with these related "slice functions" (After, First and probably others) is that they return slightly different error messages for the same issue. Maybe we can get some input from the Go compiler and start clean this up. https://play.golang.org/p/P8aYI5j7lxp package main
import (
"fmt"
)
func main() {
slice(-1, 2)
slice(0, 20)
}
var s = []string{"a", "b", "c"}
func slice(a, b int) {
defer func() {
if r := recover(); r != nil {
fmt.Printf("%d:%d => %s\n", a, b, r)
}
}()
fmt.Println(s[a:b])
} Which prints: -1:2 => runtime error: slice bounds out of range [-1:]
0:20 => runtime error: slice bounds out of range [:20] with capacity 3 So for your After example, maybe:
|
Sounds good. |
I was thinking that once #6419 is closed, I will change also to
as it would have the same condition as first then. |
I agree. |
Modified the messages functions after, first, and last threw on being passed invalid parameters (index or limit) to be more standardised and resemble what Go compiler would throw. Fixes gohugoio#6415
Modified the messages functions after, first, and last threw on being passed invalid parameters (index or limit) to be more standardised and resemble what Go compiler would throw. Fixes gohugoio#6415
Modified the messages functions after, first, and last threw on being passed invalid parameters (index or limit) to be more standardised and resemble what Go compiler would throw. Fixes #6415
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue description
On passing negative indices, throws error message which does not accurately explain the error. Something like "cannot return slice of elements after a negative index" would be more explanatory in my opinion. Any suggestions?
If this gets the approval, I will be more than happy to submit a PR.
What version of Hugo are you using (
hugo version
)?Does this issue reproduce with the latest release?
Yes
The text was updated successfully, but these errors were encountered: