monet
monet copied to clipboard
Runtime panic if there are no posts in the database
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 579841097ddf2419a39c1a842b0bf66a146aa0ec (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.
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?
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.