f-46: config: fail loudly on an unreadable config file #46
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
8a04f6f7f6
commit
a220cce77e
2 changed files with 33 additions and 1 deletions
|
|
@ -1,6 +1,10 @@
|
|||
package configuration
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
|
|
@ -86,7 +90,9 @@ func LoadConfig(path string) (*Config, error) {
|
|||
v.SetDefault("logger.level", "info")
|
||||
v.SetDefault("logger.debug", false)
|
||||
|
||||
v.ReadInConfig()
|
||||
if err := v.ReadInConfig(); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return nil, fmt.Errorf("read %s: %w", path, err)
|
||||
}
|
||||
|
||||
var cfg Config
|
||||
if err := v.Unmarshal(&cfg); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue