gin icon indicating copy to clipboard operation
gin copied to clipboard

fix(tree): Keep panic infos consistent when wildcard type build faild

Open kingcanfish opened this issue 4 months ago • 1 comments

fix(tree): Keep panic infos consistent when wildcard type build faild

When I run the demo1

// demo1
func main() {
	router := gin.Default()
	router.GET("/abc/bar", nil)
	router.GET("/abc/x*z", nil)

	router.Run("localhost:8080")
}

it got the panic:panic: no / before catch-all in path '/abc/x*z'

but when i run the demo2

// demo2
func main() {
	router := gin.Default()
	router.GET("/abc/bar", nil)
	router.GET("/abc/b*r", nil)

	router.Run("localhost:8080")
} 

it got the panic: panic: runtime error: index out of range [-1] Although the end result is the same(panic), the different panic informations may cause some confusion.

So, add the i < 0 condition to keep the panic infos same

kingcanfish avatar Oct 17 '24 07:10 kingcanfish