From ba4840c52becf73c2749c9ef0f2f09ed0b9d5c7f Mon Sep 17 00:00:00 2001 From: Niall Sheridan Date: Sun, 12 Feb 2017 22:24:33 +0000 Subject: Update dependencies --- .../pelletier/go-toml/tomltree_conversions.go | 32 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'vendor/github.com/pelletier/go-toml/tomltree_conversions.go') diff --git a/vendor/github.com/pelletier/go-toml/tomltree_conversions.go b/vendor/github.com/pelletier/go-toml/tomltree_conversions.go index db3da0d..fc8f22b 100644 --- a/vendor/github.com/pelletier/go-toml/tomltree_conversions.go +++ b/vendor/github.com/pelletier/go-toml/tomltree_conversions.go @@ -87,7 +87,7 @@ func toTomlValue(item interface{}, indent int) string { case nil: return "" default: - panic(fmt.Sprintf("unsupported value type %T: %v", value, value)) + panic(fmt.Errorf("unsupported value type %T: %v", value, value)) } } @@ -154,6 +154,23 @@ func (t *TomlTree) toToml(indent, keyspace string) string { return strings.Join(resultChunks, "") } +// Same as ToToml(), but does not panic and returns an error +func (t *TomlTree) toTomlSafe(indent, keyspace string) (result string, err error) { + defer func() { + if r := recover(); r != nil { + result = "" + switch x := r.(type) { + case error: + err = x + default: + err = fmt.Errorf("unknown panic: %s", r) + } + } + }() + result = t.toToml(indent, keyspace) + return +} + func convertMapStringString(in map[string]string) map[string]interface{} { result := make(map[string]interface{}, len(in)) for k, v := range in { @@ -170,15 +187,18 @@ func convertMapInterfaceInterface(in map[interface{}]interface{}) map[string]int return result } -// ToString is an alias for String -func (t *TomlTree) ToString() string { - return t.String() +// ToString generates a human-readable representation of the current tree. +// Output spans multiple lines, and is suitable for ingest by a TOML parser. +// If the conversion cannot be performed, ToString returns a non-nil error. +func (t *TomlTree) ToString() (string, error) { + return t.toTomlSafe("", "") } // String generates a human-readable representation of the current tree. -// Output spans multiple lines, and is suitable for ingest by a TOML parser +// Alias of ToString. func (t *TomlTree) String() string { - return t.toToml("", "") + result, _ := t.ToString() + return result } // ToMap recursively generates a representation of the current tree using map[string]interface{}. -- cgit v1.2.3