koanf icon indicating copy to clipboard operation
koanf copied to clipboard

Access to ErrorUnused is Impractical

Open dmullis opened this issue 1 year ago • 2 comments

Referring to https://github.com/knadh/koanf/issues/189:

What bothers me with this solution is that I have to take the copy paste the default configuration chosen by koanf into my code and tweak it locally.

As a user of the API, this is one of several associated bugs I tripped over. The others being:

  1. As seen in the excerpt below, if arg c.DecoderConfig is set to non-nil, 'o' is ignored; the caller must instead pass in a pointer through the Result field.
  2. The above is undocumented, users must download and read the koanf source.
  3. The comment's reference to mitchellh/mapstructure is stale; a newer fork is now linked in, and must be located to obtain authoritative info on the semantics of ErrorUnused.
koanf.go-// UnmarshalWithConf is like Unmarshal but takes configuration params in UnmarshalConf.
koanf.go-// See mitchellh/mapstructure's DecoderConfig for advanced customization
koanf.go-// of the unmarshal behaviour.
koanf.go-func (ko *Koanf) UnmarshalWithConf(path string, o interface{}, c UnmarshalConf) error {
koanf.go-    if c.DecoderConfig == nil {
koanf.go:            c.DecoderConfig = &mapstructure.DecoderConfig{
koanf.go-                    DecodeHook: mapstructure.ComposeDecodeHookFunc(
koanf.go-                            mapstructure.StringToTimeDurationHookFunc(),
koanf.go-                            textUnmarshalerHookFunc()),
koanf.go-                    Metadata:         nil,
koanf.go-                    Result:           o,
koanf.go-                    WeaklyTypedInput: true,
koanf.go-            }
koanf.go-    }
koanf.go-

dmullis avatar Jul 17 '24 17:07 dmullis

Could you please send a PR? About mapstructure, please see: https://github.com/knadh/koanf/issues/262

knadh avatar Jul 21 '24 06:07 knadh

I believe it should be changed in the underlying library. Because the problem is mixing of config params and a result 'container' in DecoderConfig.

optician avatar Sep 18 '24 06:09 optician