JoergReinhardt / gorilla

Automatically exported from code.google.com/p/gorilla
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

panic: (probably) wrong usage #28

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I found that Gorilla uses following pattern very extensively:

panic(fmt.Sprintf(...))

But this fails for me (release-branch.r60) with:

2011/11/06 12:32:28 http: panic serving @: interface conversion: string is not 
os.Error: missing method String  

Although following works for me properly:

panic(os.NewError(fmt.Sprintf(...)))

Are you able to reproduce?

Original issue reported on code.google.com by vladimir...@gmail.com on 6 Nov 2011 at 12:42

GoogleCodeExporter commented 9 years ago
What version of gorilla are you using? WIth the weekly tagged 11-02-2011 of 
both go and gorilla, I have no problem using panic(fmt.Sprintf(...)). Looks 
like a version conflict between release and weekly. It might be that you are 
using release branch r60 of go and weekly branch of gorilla (hosted at github 
(https://github.com/moraes/gorilla). Can you please confirm?

Original comment by ashokgelal on 6 Nov 2011 at 7:53

GoogleCodeExporter commented 9 years ago
I think I have both r60 branches of Go and Gorilla. Traceback looks like this 
(msg is string):

INFO     2011-11-06 20:01:53,941 dev_appserver.py:4143] "GET /about/ HTTP/1.1" 
500 -
INFO     2011-11-06 20:03:12,395 __init__.py:365] building _go_app
INFO     2011-11-06 20:03:14,123 __init__.py:351] running _go_app
2011/11/06 20:03:14 http: panic serving @: interface conversion: string is not 
os.Error: missing m
ethod String                                                                    

/tmp/appengine/google_appengine/goroot/src/pkg/http/server.go:588 (0x8082930)
/tmp/appengine/google_appengine/goroot/src/pkg/runtime/proc.c:1235 (0x80556a3)
/tmp/appengine/google_appengine/goroot/src/pkg/runtime/iface.c:134 (0x804d3c1)
/tmp/appengine/google_appengine/goroot/src/pkg/runtime/iface.c:474 (0x804dcc4)
/tmp/appengine/google_appengine/goroot/src/pkg/runtime/iface.c:489 (0x804dd54)
/tmp/appengine/google_appengine/goroot/src/pkg/template/exec.go:85 (0x8127f50)
/tmp/appengine/google_appengine/goroot/src/pkg/runtime/proc.c:1235 (0x80556a3)
tset/tset.go:20 (0x80bc982)
        urlFor: panic(msg)
/tmp/appengine/google_appengine/goroot/src/pkg/reflect/value.go:583 (0x80f8645)
/tmp/appengine/google_appengine/goroot/src/pkg/reflect/value.go:433 (0x80f7536)
/tmp/appengine/google_appengine/goroot/src/pkg/template/exec.go:495 (0x812abd3)
/tmp/appengine/google_appengine/goroot/src/pkg/template/exec.go:384 (0x8129f2d)
/tmp/appengine/google_appengine/goroot/src/pkg/template/exec.go:310 (0x812957f)
/tmp/appengine/google_appengine/goroot/src/pkg/template/exec.go:285 (0x81292ca)
/tmp/appengine/google_appengine/goroot/src/pkg/template/exec.go:115 (0x81281ed)
/tmp/appengine/google_appengine/goroot/src/pkg/template/exec.go:124 (0x8128649)
/tmp/appengine/google_appengine/goroot/src/pkg/template/exec.go:269 (0x8129221)
/tmp/appengine/google_appengine/goroot/src/pkg/template/exec.go:131 (0x81285a2)
/tmp/appengine/google_appengine/goroot/src/pkg/template/exec.go:124 (0x8128649)
/tmp/appengine/google_appengine/goroot/src/pkg/template/exec.go:103 (0x812810c)
/tmp/appengine/google_appengine/goroot/src/pkg/template/set.go:88 (0x812eeae)
tset/tset.go:69 (0x80bce9b)
        RenderTemplate: err = s.Execute(w, "layout.html", vars)

Actually I am able to call panic("message") from different place - so it looks 
that this is more specific issue. I will try to prepare minimal code that 
reproduces this...

Original comment by vladimir...@gmail.com on 6 Nov 2011 at 8:27

GoogleCodeExporter commented 9 years ago
I am able to reproduce with this code: http://paste.pocoo.org/show/504303/

test.html is just:

<p>URL: {{urlFor}}</p>

Basically I am getting such behavior if function is called from template.

Original comment by vladimir...@gmail.com on 7 Nov 2011 at 8:43

GoogleCodeExporter commented 9 years ago
My urlFor func can be simplified to this:

func urlFor() string {
    panic("fail")
}

but this works fine:

func urlFor() string {
    panic(os.NewError("fail"))
}

Original comment by vladimir...@gmail.com on 7 Nov 2011 at 8:47

GoogleCodeExporter commented 9 years ago
Looks like problem sits in recover() in goroot/src/pkg/template/exec.go:85.

Original comment by vladimir...@gmail.com on 7 Nov 2011 at 9:07

GoogleCodeExporter commented 9 years ago
Any advices how should I write template func to generate URL for named route?

Original comment by vladimir...@gmail.com on 12 Nov 2011 at 3:16