From 8c63f40f5691f982d242d30cae3a2ae1c3ea0658 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Fri, 18 Jun 2021 10:50:45 +0200 Subject: [PATCH] filter out defined variables in error --- envconf.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/envconf.go b/envconf.go index a278bc6..1093b71 100644 --- a/envconf.go +++ b/envconf.go @@ -104,12 +104,14 @@ func (c *Config) Parse() { } for k, v := range c.env { if failed && (v.parsed.err == nil) { - if v.unset { - v.parsed.err = errors.New(fmt.Sprintf(`Environment variable "%s" not found. It should have been of type %s.`, k, v.dtype)) - c.env[k] = v - } else { - v.parsed.err = errors.New(fmt.Sprintf(`Environment variable "%s" not found. Default value of "%s"(%s) used.`, k, v.value, v.dtype)) - c.env[k] = v + if v.empty { + if v.unset { + v.parsed.err = errors.New(fmt.Sprintf(`Environment variable "%s" not found. It should have been of type %s.`, k, v.dtype)) + c.env[k] = v + } else { + v.parsed.err = errors.New(fmt.Sprintf(`Environment variable "%s" not found. Default value of "%s"(%s) used.`, k, v.value, v.dtype)) + c.env[k] = v + } } } }