improve envdecode error handling

This commit is contained in:
Willy Kloucek
2022-01-03 09:43:42 +01:00
committed by Jörn Friedrich Dreyer
parent e89071200f
commit 6a03c4acba
14 changed files with 79 additions and 27 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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.")

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
}

View File

@@ -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

View File

@@ -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