aboutsummaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'config.go')
-rw-r--r--config.go42
1 files changed, 29 insertions, 13 deletions
diff --git a/config.go b/config.go
index 6efa90d..bc0fa6a 100644
--- a/config.go
+++ b/config.go
@@ -1,7 +1,6 @@
package planr
import (
- // "fmt"
"log"
"github.com/BurntSushi/toml"
)
@@ -41,7 +40,7 @@ type InheritableConfig interface {
// A parser function takes a blob of TOML and decodes it into
// configuration relevant to an adapter
-type TomlParser func (toml.Primitive) InheritableConfig
+type TomlParser func (toml.Primitive) (InheritableConfig, error)
// The name under which an adapter registers corresponds
// to a table under the super-table adapters. All corresponding
@@ -134,7 +133,10 @@ func (child *Defaults) Inherit(p interface{}) {
// according to methods registered with the runner
// Once parsed, they are stored alongside the registered name to determine
// which adapter will receive the configuration
-func (defaults *Defaults) decodeAdapters(adapters []AdapterConfig, asDefault bool) {
+func (defaults *Defaults) decodeAdapters(
+ adapters []AdapterConfig,
+ asDefault bool,
+) error {
defaults.configs_ = &adapters
defaults.adapters_ = make(map[string]InheritableConfig)
@@ -144,40 +146,54 @@ func (defaults *Defaults) decodeAdapters(adapters []AdapterConfig, asDefault boo
if exists {
var parsed InheritableConfig
+ var err error
if asDefault {
- parsed = config.ParseDefaultConfig(primitive)
+ parsed, err = config.ParseDefaultConfig(primitive)
} else {
- parsed = config.ParseConfig(primitive)
+ parsed, err = config.ParseConfig(primitive)
+ }
+
+ if err != nil {
+ return err
}
defaults.adapters_[config.Name] = parsed
}
}
}
+
+ return nil
}
// Decode defaults.toml
-func DecodeDefaults(path string, adapterCfg []AdapterConfig) Defaults {
+func DecodeDefaults(path string, adapterCfg []AdapterConfig) (Defaults, error) {
defaults := Defaults { }
+
+
if _, err := toml.DecodeFile(path, &defaults); err != nil {
- log.Fatal(err)
+ return defaults, err
+ }
+
+ if err := defaults.decodeAdapters(adapterCfg, true); err != nil {
+ return defaults, err
}
- defaults.decodeAdapters(adapterCfg, true)
- return defaults
+ return defaults, nil
}
// Decode an individual unit
-func DecodeConfig(path string, adapterCfg []AdapterConfig) TestCaseConfig {
+func DecodeConfig(path string, adapterCfg []AdapterConfig) (TestCaseConfig, error) {
config := TestCaseConfig { }
if _, err := toml.DecodeFile(path, &config); err != nil {
- log.Fatal(err)
+ return config, nil
}
- config.decodeAdapters(adapterCfg, false)
+ if err := config.decodeAdapters(adapterCfg, false); err != nil {
+ return config, err
+ }
- return config
+ return config, nil
}