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

Run time panic when compiling with vgo #330

Closed
Daniel-M opened this issue Jul 3, 2018 · 6 comments
Closed

Run time panic when compiling with vgo #330

Daniel-M opened this issue Jul 3, 2018 · 6 comments

Comments

@Daniel-M
Copy link

Daniel-M commented Jul 3, 2018

Details

The same go-chi implementation shows errors at runtime related to the tool used to compile it. When compiled with go build the code snippet (below) runs as expected. When compiled with vgo build the binary throws a panic

Error

panic: chi: unsupported middleware signature: func(chi.Handler) chi.Handler

goroutine 1 [running]:
github.com/go-chi/chi.assertMiddleware(0x7bb3e0, 0x8628f8, 0x1, 0xc42022b720)

System details

Ways of reproduce the error

I have the following code snippet:

package main

import (
	"net/http"
	"github.com/go-chi/chi"
	"github.com/go-chi/chi/middleware"
)


func main() {
	r := chi.NewRouter()
	r.Use(middleware.Logger)
	r.Use(middleware.Recoverer)

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

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

Compile with,

vgo build

Then run the binary and the panic above is thrown

Compile as,

go build

Then run the binary and the panic never happens

@Daniel-M
Copy link
Author

Daniel-M commented Jul 3, 2018

Could it be that, somehow, vgo rewrites the middleware signature from the expected http.handler to the chi.Handler? the relevant portion of the code which throws the panic is,

(line 83 of github.com/go-chi/chi@v1.0.0/util.go)

// Runtime type checking of the middleware signature
func assertMiddleware(middleware interface{}) interface{} {
	switch t := middleware.(type) {
	default:
		panic(fmt.Sprintf("chi: unsupported middleware signature: %T", t))
	case func(http.Handler) http.Handler:
	case func(Handler) Handler:
	}
	return middleware
}

@VojtechVitek
Copy link
Contributor

Your vgo is probably pulling chi v1.0.0 instead of latest v3.3.2. This is vgo problem.. See #327 and golang/go#25967

@Daniel-M
Copy link
Author

Daniel-M commented Jul 3, 2018

@VojtechVitek Actually just found out this by myself and was about to close this issue

The solution was to change go.mod as:

require (
	github.com/go-chi/chi v2.0.0
	github.com/pressly/chi v2.0.0
        ...
)

@Daniel-M Daniel-M closed this as completed Jul 3, 2018
@VojtechVitek
Copy link
Contributor

note that v2.0.0 is old version that is not maintained anymore :)

@Daniel-M
Copy link
Author

Daniel-M commented Jul 3, 2018

@VojtechVitek Oh, thanks, which version should I use then?

@Daniel-M
Copy link
Author

Daniel-M commented Jul 3, 2018

The following worked for me

require (
    github.com/go-chi/chi v3.3.2
...`

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