Return error instead of panic in Lua encoder

This commit is contained in:
Kim Alvefur 2023-08-02 12:20:07 +02:00
parent f544580692
commit 58d14f7ea9

View File

@ -1,6 +1,7 @@
package yqlib package yqlib
import ( import (
"fmt"
"io" "io"
"strings" "strings"
@ -183,7 +184,7 @@ func (le *luaEncoder) encodeAny(writer io.Writer, node *yaml.Node) error {
return writeString(writer, strings.ToLower(node.Value)) return writeString(writer, strings.ToLower(node.Value))
case "!!int": case "!!int":
if strings.HasPrefix(node.Value, "0o") { if strings.HasPrefix(node.Value, "0o") {
panic("Lua encoder NYI -- octal") // FIXME return fmt.Errorf("Lua encoder NYI -- octal") // FIXME
} }
return writeString(writer, strings.ToLower(node.Value)) return writeString(writer, strings.ToLower(node.Value))
case "!!float": case "!!float":
@ -198,7 +199,7 @@ func (le *luaEncoder) encodeAny(writer io.Writer, node *yaml.Node) error {
return writeString(writer, node.Value) return writeString(writer, node.Value)
} }
default: default:
panic("Lua encoder NYI -- " + node.ShortTag()) return fmt.Errorf("Lua encoder NYI -- %s", node.ShortTag())
} }
case yaml.DocumentNode: case yaml.DocumentNode:
err := writeString(writer, le.docPrefix) err := writeString(writer, le.docPrefix)
@ -211,7 +212,7 @@ func (le *luaEncoder) encodeAny(writer io.Writer, node *yaml.Node) error {
} }
return writeString(writer, le.docSuffix) return writeString(writer, le.docSuffix)
default: default:
panic("Lua encoder NYI -- " + node.ShortTag()) return fmt.Errorf("Lua encoder NYI -- %s", node.ShortTag())
} }
} }