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

Runtime panic if there are no posts in the database #4

Open
alexander-bauer opened this issue May 30, 2013 · 2 comments
Open

Runtime panic if there are no posts in the database #4

alexander-bauer opened this issue May 30, 2013 · 2 comments

Comments

@alexander-bauer
Copy link

2013/05/30 17:26:17 GET /
2013/05/30 17:26:17 Handler crashed with error runtime error: index out of range
2013/05/30 17:26:17 /usr/lib/go/src/pkg/runtime/panic.c 229
2013/05/30 17:26:17 /usr/lib/go/src/pkg/runtime/panic.c 487
2013/05/30 17:26:17 /usr/lib/go/src/pkg/runtime/panic.c 442
2013/05/30 17:26:17 /home/sasha/dev/go/src/github.com/jmoiron/monet/blog/app.go 71
2013/05/30 17:26:17 /usr/lib/go/src/pkg/reflect/value.go 474
2013/05/30 17:26:17 /usr/lib/go/src/pkg/reflect/value.go 345
2013/05/30 17:26:17 /home/sasha/dev/go/src/github.com/hoisie/web/server.go 196
2013/05/30 17:26:17 /home/sasha/dev/go/src/github.com/hoisie/web/server.go 305
2013/05/30 17:26:17 /home/sasha/dev/go/src/github.com/hoisie/web/server.go 87
2013/05/30 17:26:17 /home/sasha/dev/go/src/github.com/hoisie/web/server.go 82
2013/05/30 17:26:17 /usr/lib/go/src/pkg/net/http/server.go 1416
2013/05/30 17:26:17 /usr/lib/go/src/pkg/net/http/server.go 1517
2013/05/30 17:26:17 /usr/lib/go/src/pkg/net/http/server.go 1096
2013/05/30 17:26:17 /usr/lib/go/src/pkg/runtime/proc.c 1223

The notable line here is in app.go. As of 5798410 (the current version), it is.

post = &posts[0]

There is currently no check to make certain that len(posts) > 0, and this causes a runtime error.

@keybits
Copy link

keybits commented Sep 15, 2013

I too have this issue and can't work out how to fix it. I tried inserting a post manually into the database but I get the same error.

Any suggestions on how to fix?

@jmoiron
Copy link
Owner

jmoiron commented Sep 17, 2013

Hrm, I originally had a bunch to pull in from a previous blog I wrote; I'll make sure that it'l work with 0 posts.

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

3 participants