From b2f0878c5a56af78127dbd6b9cd1e337d58b363f Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Fri, 18 Jun 2021 11:48:40 +0200 Subject: [PATCH] improve error message --- envconf.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/envconf.go b/envconf.go index b8cbf88..49f83dc 100644 --- a/envconf.go +++ b/envconf.go @@ -102,14 +102,14 @@ func (c *Config) Parse() { c.env[k] = v } } - for k, v := range c.env { - if failed && (v.parsed.err == nil) { - if v.unset { + if failed { + for k, v := range c.env { + if (v.parsed.err == nil) && v.unset { if v.empty { 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)) + v.parsed.err = errors.New(fmt.Sprintf(`Environment variable "%s" not found. Default value "%s" of type %s used.`, k, v.value, v.dtype)) c.env[k] = v } }