Added error context for parsing of subtrees

This commit is contained in:
eanderton
2014-08-06 08:20:53 -04:00
parent 6db660fed5
commit 1f8a8cbc06
3 changed files with 9 additions and 4 deletions
+5 -2
View File
@@ -142,11 +142,13 @@ func (t *TomlTree) SetPath(keys []string, value interface{}) {
//
// e.g. passing a.b.c will create (assuming tree is empty) tree[a], tree[a][b]
// and tree[a][b][c]
func (t *TomlTree) createSubTree(key string) {
//
// Returns nil on success, error object on failure
func (t *TomlTree) createSubTree(key string) error{
subtree := t
for _, intermediate_key := range strings.Split(key, ".") {
if intermediate_key == "" {
panic("empty intermediate table")
return fmt.Errorf("empty intermediate table")
}
_, exists := (*subtree)[intermediate_key]
if !exists {
@@ -155,6 +157,7 @@ func (t *TomlTree) createSubTree(key string) {
}
subtree = ((*subtree)[intermediate_key]).(*TomlTree)
}
return nil
}
// encodes a string to a TOML-compliant string value