diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index c6d70c96db..05b3e83510 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" "strings" @@ -79,8 +80,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } // sanitize config diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 5fe6aefdc9..f72d940c1b 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" "github.com/owncloud/ocis/glauth/pkg/config" @@ -70,8 +71,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 6b0fbedf8f..6a4ae2bbe9 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" "github.com/owncloud/ocis/graph-explorer/pkg/config" @@ -68,8 +69,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 565aa710fb..41b7239309 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -69,8 +70,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index c59652ff43..e346e4b1f2 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" "github.com/owncloud/ocis/idp/pkg/config" @@ -71,8 +72,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/ocis-pkg/config/envdecode/envdecode_test.go b/ocis-pkg/config/envdecode/envdecode_test.go index 54ac86decf..d8cec54c93 100644 --- a/ocis-pkg/config/envdecode/envdecode_test.go +++ b/ocis-pkg/config/envdecode/envdecode_test.go @@ -411,7 +411,7 @@ func TestDecodeErrors(t *testing.T) { var tcrd testConfigRequiredDefault defer func() { - recover() + _ = recover() }() _ = Decode(&tcrd) t.Fatal("This should not have been reached. A panic should have occured.") diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index 232c18ab24..034061824b 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -1,6 +1,7 @@ package command import ( + "errors" "os" "github.com/owncloud/ocis/ocis-pkg/config" @@ -62,8 +63,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 994e5e8898..3f17fb049e 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -72,8 +73,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 7bd07dfde8..02ab99c584 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -71,8 +72,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index c6091ef905..9ee08aef21 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -72,8 +73,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index be613a9f75..ca3d05bb2b 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -72,8 +73,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index 4236c1098b..fbaaeba51d 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -72,8 +73,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil } diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index 371c3337e4..b56960a86a 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -70,8 +71,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index 224823e019..e39d64cd0d 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -2,6 +2,7 @@ package command import ( "context" + "errors" "os" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" @@ -70,8 +71,11 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } // load all env variables relevant to the config in the current context. - if err := envdecode.Decode(cfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { - return err + if err := envdecode.Decode(cfg); err != nil { + // no environment variable set for this config is an expected "error" + if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { + return err + } } return nil