Skip to content

panic when koanf.Get a path which is set with nil pointer value #396

@Asakuri

Description

@Asakuri

Describe the bug
If I use koanf.Set to set a nil struct pointer, it panics when I try to get the value by koanf.Get
This may not be a typical use case, but if Set is allowed to set a nil struct pointer, it seems like a bug Get cannot get the corresponding value from the same path.

To Reproduce

package main

import (
	"github.com/knadh/koanf/v2"
)

type Test struct{}

func main() {
	var t *Test
	k := koanf.New(".")
	k.Set("a", t)
	k.Get("a") // panic: reflect: call of reflect.Value.Set on zero Value
}

Expected behavior
No panic and get the nil struct pointer

Please provide the following information):

  • OS: linux
  • Koanf Version: 2.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions