Skip to content

Panic when dumping a struct with a private map field #18

@bradleyjkemp

Description

@bradleyjkemp

When dumping a struct that has a private field containing a map litter panics because the map key sort function calls .Interface() on an unexported value.
Repro case:

package main

import (
	"github.com/sanity-io/litter"
)

type privateMap struct {
	private map[string]map[string]bool
}

func main() {
	litter.Options{
		HidePrivateFields: false,
		StripPackageNames: true,
	}.Dump(&privateMap{
		private: map[string]map[string]bool{
			"panics": {
				"panics": true,
			},
			"test": {
				"test": true,
			},
		},
	})
}

Results in error:

&privateMap{
  private: map[string]map[string]bool{
panic: reflect.Value.Interface: cannot return value obtained from unexported field or method

With the stack trace attributing this panic to dump.go:392

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