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

envconfig does not initialize pointer type which implements TextUnmarshaler #157

Open
cuonglm opened this issue Nov 27, 2019 · 0 comments · May be fixed by #158
Open

envconfig does not initialize pointer type which implements TextUnmarshaler #157

cuonglm opened this issue Nov 27, 2019 · 0 comments · May be fixed by #158

Comments

@cuonglm
Copy link

cuonglm commented Nov 27, 2019

This program:

package main

import (
	"fmt"
	"log"

	"github.com/kelseyhightower/envconfig"
)

type U string

func (u *U) UnmarshalText(b []byte) error {
	*u = U(string(b))
	return nil
}

type Env struct {
	Users []*U
}

func main() {
	var e Env
	err := envconfig.Process("myapp", &e)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Println("Users:")
	for _, u := range e.Users {
		fmt.Printf("  %s\n", *u)
	}
}

panics:

$ go run main.go
go: found github.com/kelseyhightower/envconfig in github.com/kelseyhightower/envconfig v1.4.0
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x10f9af7]

goroutine 1 [running]:
main.(*U).UnmarshalText(0x0, 0xc00010c0b0, 0x3, 0x8, 0x3, 0x8)
	/Users/cuonglm/main.go:13 +0x57
github.com/kelseyhightower/envconfig.processField(0xc00001822c, 0x3, 0x11160c0, 0xc00012e180, 0x196, 0xc00012e180, 0x196)
	/Users/cuonglm/go/pkg/mod/github.com/kelseyhightower/[email protected]/envconfig.go:251 +0x1262
github.com/kelseyhightower/envconfig.processField(0xc00001822c, 0xe, 0x1108c80, 0xc00012e080, 0x197, 0x0, 0x0)
	/Users/cuonglm/go/pkg/mod/github.com/kelseyhightower/[email protected]/envconfig.go:312 +0xf83
github.com/kelseyhightower/envconfig.Process(0x11375da, 0x5, 0x1105da0, 0xc00012e080, 0x1105520, 0x1162780)
	/Users/cuonglm/go/pkg/mod/github.com/kelseyhightower/[email protected]/envconfig.go:215 +0x47a
main.main()
	/Users/cuonglm/main.go:23 +0x73
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

Successfully merging a pull request may close this issue.

1 participant