Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

More descriptive configloader error messages #342

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions common/configloader/configloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import (
"os"
)

var ErrNotSet = errors.New("The value for the given key was not set")
var ErrDecodeFailed = errors.New("The value for the given key could not be decoded")
var ErrLoadFailed = errors.New("Unable to load config")

/*
Used to load a key value configuration
Expand All @@ -33,7 +30,7 @@ func Load(config_path string) (*ConfigLoader, error) {
uri, err := url.Parse(config_path)

if err != nil {
return nil, ErrLoadFailed
return nil, errors.New("Unable to load config path: " + config_path)
}

var config_contents []byte
Expand All @@ -46,11 +43,11 @@ func Load(config_path string) (*ConfigLoader, error) {
case "https":
config_contents, err = loadFromHttps(config_path)
default:
return nil, ErrLoadFailed
return nil, errors.New("Unable to load config path: " + config_path)
}

if err != nil {
return nil, ErrLoadFailed
return nil, errors.New("Unable to load config path: " + config_path)
}

loader := ConfigLoader{
Expand All @@ -60,7 +57,7 @@ func Load(config_path string) (*ConfigLoader, error) {
err = json.Unmarshal(config_contents, &loader.parsedConfig)

if err != nil {
return nil, ErrLoadFailed
return nil, errors.New("Unable to load config path: " + config_path)
}

return &loader, nil
Expand All @@ -80,13 +77,13 @@ func (loader *ConfigLoader) Get(key string) (string, error) {
raw_value, exists := loader.parsedConfig[key]

if !exists {
return "", ErrNotSet
return "", errors.New("The value for the given key: " + key + " was not set")
}

err := json.Unmarshal(*raw_value, &value)

if err != nil {
return "", ErrDecodeFailed
return "", errors.New("The value for the given key: " + key + " could not be decoded")
}

return value, nil
Expand All @@ -106,7 +103,7 @@ func (loader *ConfigLoader) ParseInto(key string, out interface{}) error {
raw_value, exists := loader.parsedConfig[key]

if !exists {
return ErrNotSet
return errors.New("The value for the given key: " + key + " was not set")
}

return json.Unmarshal(*raw_value, out)
Expand Down