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

Panic on doc generate when using middleware.Profiler #153

Closed
zbindenren opened this issue Feb 13, 2017 · 8 comments
Closed

Panic on doc generate when using middleware.Profiler #153

zbindenren opened this issue Feb 13, 2017 · 8 comments

Comments

@zbindenren
Copy link

Hi

When using the profiler middleware in combination with the docgen package, I get a panic.

main.go:

...
func main() {
        flag.Parse()

        r := chi.NewRouter()

        r.Use(middleware.RequestID)
        r.Use(middleware.Logger)
        r.Use(middleware.Recoverer)
        r.Mount("/debug", middleware.Profiler()) // <- this is new

        r.Get("/", func(w http.ResponseWriter, r *http.Request) {
                w.Write([]byte("root."))
        })
...

panic:

panic: reflect: call of reflect.Value.Pointer on string Value

goroutine 1 [running]:
panic(0x754b80, 0xc420323300)
        /usr/lib/go/src/runtime/panic.go:500 +0x1a1
reflect.Value.Pointer(0x750660, 0xc420120150, 0x98, 0xc420120150)
        /usr/lib/go/src/reflect/value.go:1258 +0x12f
github.com/pressly/chi/docgen.getCallerFrame(0x750660, 0xc420120150, 0x5)
        /home/rz/golang/src/github.com/pressly/chi/docgen/util.go:11 +0x6f
github.com/pressly/chi/docgen.buildFuncInfo(0x750660, 0xc420120150, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/rz/golang/src/github.com/pressly/chi/docgen/builder.go:85 +0x8e
github.com/pressly/chi/docgen.buildDocRouter(0x7fab6d6e30b0, 0xc420128120, 0xc4202f2f60, 0x0, 0xc4202f2f60, 0xc420211650)
        /home/rz/golang/src/github.com/pressly/chi/docgen/builder.go:71 +0x895
github.com/pressly/chi/docgen.buildDocRouter(0x7fab6d6e30b0, 0xc4201280c0, 0xc42000c0c7, 0xf, 0x7af600, 0x956700)
        /home/rz/golang/src/github.com/pressly/chi/docgen/builder.go:45 +0x3fd
github.com/pressly/chi/docgen.BuildDoc(0x7fab6d6e30b0, 0xc4201280c0, 0xc4201280c0, 0x7fab6d6e30b0, 0xc4201280c0, 0x8, 0xc42004de98, 0x4eb52c)
        /home/rz/golang/src/github.com/pressly/chi/docgen/builder.go:23 +0xf4
github.com/pressly/chi/docgen.(*MarkdownDoc).Generate(0xc420183e18, 0xc420135900, 0x3ff)
        /home/rz/golang/src/github.com/pressly/chi/docgen/markdown.go:56 +0x6d
github.com/pressly/chi/docgen.MarkdownRoutesDoc(0x95e0e0, 0xc4201280c0, 0x7c7251, 0x16, 0x7d1103, 0x31, 0x0, 0x0, 0x1d, 0x0)
        /home/rz/golang/src/github.com/pressly/chi/docgen/markdown.go:41 +0x9c
main.main()
        /tmp/bla/main.go:67 +0x29b
@pkieltyka
Copy link
Member

Im unable to reproduce the above issue with the latest master, but if you see it comes up again please re-open the ticket and I'll take a look asap.

@zbindenren
Copy link
Author

zbindenren commented Sep 7, 2017

@pkieltyka I have the same issue with the latest releases. I opened the issue with the reproducer for the docgen repo here.

@ladydascalie
Copy link

I have this issue as well on the latest releases

@VojtechVitek
Copy link
Contributor

Do you guys have full reproducer?

@ladydascalie
Copy link

@VojtechVitek the following contrived example shows the exact panic received:

main.go:

package main

import (
	"net/http"

	"github.com/go-chi/chi"
	"github.com/go-chi/chi/middleware"
	"github.com/go-chi/docgen"
)

func main() {
	r := chi.NewRouter()
	r.Mount("/debug", middleware.Profiler())
	r.Get("/bla", blaHandler)

	docgen.JSONRoutesDoc(r)

	http.ListenAndServe(":8080", r)
}

func blaHandler(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(204)
}

trace:

panic: reflect: call of reflect.Value.Pointer on string Value

goroutine 1 [running]:
reflect.Value.Pointer(0x138b5c0, 0xc420010cc0, 0x98, 0xc420010cc0)
	/usr/local/go/src/reflect/value.go:1276 +0x185
github.com/go-chi/docgen.getCallerFrame(0x138b5c0, 0xc420010cc0, 0x16117a0)
	/Users/benjamincable/go/src/github.com/go-chi/docgen/funcinfo.go:70 +0x6f
github.com/go-chi/docgen.buildFuncInfo(0x138b5c0, 0xc420010cc0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/benjamincable/go/src/github.com/go-chi/docgen/builder.go:85 +0x91
github.com/go-chi/docgen.buildDocRouter(0x15e3d20, 0xc4201380e0, 0xc420081b30, 0x0, 0xc420081b30, 0xf)
	/Users/benjamincable/go/src/github.com/go-chi/docgen/builder.go:71 +0x7f3
github.com/go-chi/docgen.buildDocRouter(0x15e3d20, 0xc420138070, 0xc42001a1a7, 0x17, 0x4, 0x15e0a20)
	/Users/benjamincable/go/src/github.com/go-chi/docgen/builder.go:45 +0x427
github.com/go-chi/docgen.BuildDoc(0x15e3d20, 0xc420138070, 0x3ff, 0x15e3d20, 0xc4201380e0, 0xc4201380e0, 0xc42012bf28, 0x12ab7ce)
	/Users/benjamincable/go/src/github.com/go-chi/docgen/builder.go:23 +0xf4
github.com/go-chi/docgen.JSONRoutesDoc(0x15e3d20, 0xc420138070, 0x4, 0x141e7e0)
	/Users/benjamincable/go/src/github.com/go-chi/docgen/docgen.go:58 +0x42
main.main()
	/Users

@VojtechVitek VojtechVitek reopened this Oct 20, 2017
@pkieltyka
Copy link
Member

pkieltyka commented Nov 21, 2017

@ladydascalie I've tried to run your example using chi v3.3.1 on go 1.9.2 and couldn't reproduce the issue - the docs generated fine. Would you mind confirming when you have a chance?

@ladydascalie
Copy link

Sorry, I missed the notification for this before.

Running it on the latest version works properly for me!

@pkieltyka
Copy link
Member

@ladydascalie awesome thanks for confirming!

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

4 participants