Skip to content

Panic when dumping a gorilla named route #31

@fgm

Description

@fgm

Seems similar to #18 but still happens with current version:

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/gorilla/mux"
	"github.com/sanity-io/litter"
)

func main() {
	r := mux.NewRouter()

	r.HandleFunc(`/foo`, AnyHandler).Name("named")
	r.HandleFunc("/", AnyHandler).Name("front")

	srv := &http.Server{
		Handler: r,
		Addr:    "127.0.0.1:8000",
	}

	log.Fatal(srv.ListenAndServe())
}

func AnyHandler(w http.ResponseWriter, r *http.Request) {
	route := mux.CurrentRoute(r)
	litter.Config.HidePrivateFields = false
	fmt.Fprintln(w, route.GetName())
	defer func() {
		p := recover()
		if p != nil {
			fmt.Printf("Recovered: %#v\n", p)
		}
	}()
	litter.Sdump(route)
}
  • Navigate to either / or /foo
  • Panics with: "reflect.Value.Interface: cannot return value obtained from unexported field or method"
  • Does not panic if only one of the routes is handled
  • Does not panic if either of the routes is not named

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions