Skip to content

Commit

Permalink
Merge pull request #2 from farwydi/master
Browse files Browse the repository at this point in the history
feat: Add visibility and context to error handling
  • Loading branch information
snovichkov committed Apr 9, 2023
2 parents 17319e3 + b5eaad5 commit af68910
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package viper
import (
"context"
"errors"
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -148,14 +149,20 @@ func (b *Bundle) provideViper(ctx context.Context, flagSet *pflag.FlagSet) (_ *v

var configFile string
if configFile, err = flagSet.GetString("config"); err != nil {
return nil, err
return nil, fmt.Errorf("unable to get config flag value : %w", err)
}

if len(configFile) > 0 {
b.viper.SetConfigFile(configFile)
}

return b.viper, b.viper.ReadInConfig()
err = b.viper.ReadInConfig()
if err != nil {
return nil, fmt.Errorf("unable to read config file : '%s' : %w",
configFile, err)
}

return b.viper, nil
}

func (b *Bundle) provideFlagSet() (*pflag.FlagSet, error) {
Expand Down

0 comments on commit af68910

Please sign in to comment.