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

Server panic when query page[size]=0 #305

Open
imhuytq opened this issue Nov 11, 2017 · 2 comments
Open

Server panic when query page[size]=0 #305

imhuytq opened this issue Nov 11, 2017 · 2 comments

Comments

@imhuytq
Copy link

imhuytq commented Nov 11, 2017

When calling PaginatedFindAll with query page[size]=0, the server returns the following error:

http: panic serving 172.24.0.1:41332: runtime error: integer divide by zero
goroutine 260 [running]:
net/http.(*conn).serve.func1(0xc4200f3ae0)
	/usr/local/go/src/net/http/server.go:1721 +0xd0
panic(0x7f4540, 0xa619c0)
	/usr/local/go/src/runtime/panic.go:489 +0x2cf
github.com/imhuytq/a/vendor/github.com/manyminds/api2go.paginationQueryParams.getLinks(0xc42015ef1b, 0x1, 0xc42015ef28, 0x1, 0x0, 0x0, 0x0, 0x0, 0xc42000b100, 0x2, ...)
	/go/src/github.com/imhuytq/a/vendor/github.com/manyminds/api2go/api.go:110 +0xec1
github.com/imhuytq/a/vendor/github.com/manyminds/api2go.(*resource).handleIndex(0xc4203627c0, 0xa40460, 0xc42000e1d0, 0xa3e480, 0xc420462c40, 0xc42000b100, 0x85e51e, 0x1, 0xa390c0, 0xc4203515f0, ...)
	/go/src/github.com/imhuytq/a/vendor/github.com/manyminds/api2go/api.go:479 +0x567
github.com/imhuytq/a/vendor/github.com/manyminds/api2go.(*API).addResource.func3(0xa3e480, 0xc420462c40, 0xc42000b100, 0xc4207e10b0)
	/go/src/github.com/imhuytq/a/vendor/github.com/manyminds/api2go/api.go:262 +0x198
github.com/imhuytq/a/vendor/github.com/manyminds/api2go/routing.HTTPRouter.Handle.func1(0xa3e480, 0xc420462c40, 0xc42000b100, 0x0, 0x0, 0x0)
	/go/src/github.com/imhuytq/a/vendor/github.com/manyminds/api2go/routing/httprouter.go:22 +0x151
github.com/imhuytq/a/vendor/github.com/julienschmidt/httprouter.(*Router).ServeHTTP(0xc420362540, 0xa3e480, 0xc420462c40, 0xc42000b100)
	/go/src/github.com/imhuytq/a/vendor/github.com/julienschmidt/httprouter/router.go:344 +0x813
net/http.serverHandler.ServeHTTP(0xc42009b8c0, 0xa3e480, 0xc420462c40, 0xc42000b100)
	/usr/local/go/src/net/http/server.go:2568 +0x92
net/http.(*conn).serve(0xc4200f3ae0, 0xa3eac0, 0xc42015ee40)
	/usr/local/go/src/net/http/server.go:1825 +0x612
created by net/http.(*Server).Serve
	/usr/local/go/src/net/http/server.go:2668 +0x2ce

I think PaginatedFindAll should return the defaultSize. When query page[size]=0 will assign size = defaultSize.
Another problem is that when I want to limit the size (eg max = 10), what should I do?

@sharpner
Copy link
Member

Oh that is not supposed to happen. Thanks for reporting! Instead of implicitly assuming that zero should be the defaultSize, I'd rather handle invalid cases with a bad request. If you'd like or it's urgent you you open a PR with a test, but if not, we will take a look at it :)

@imhuytq
Copy link
Author

imhuytq commented Nov 11, 2017

I validated the page[size] parameter in the PaginatedFindAll function and returned a BadRequest error message if it was zero. This problem is not very serious, but you should check back later. I think the way to solve this problem may be related to #306.

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

No branches or pull requests

2 participants