Fix: wrap error

This commit is contained in:
kayos@tcp.direct 2024-07-22 01:53:06 -07:00
parent 3008d84b9a
commit d7ff3c3107
No known key found for this signature in database
GPG Key ID: 4B841471B4BEE979
2 changed files with 6 additions and 3 deletions

View File

@ -153,13 +153,14 @@ func handleArray(valueString string) (value any) {
if intErr == nil {
intVals = append(intVals, avalInt)
}
}
if len(intVals) == len(asplit) && len(intVals) > 0 {
value = intVals
} else {
value = asplit
}
return value
}
@ -276,6 +277,7 @@ func (d *decoder) readData() error {
}
myTable, mapAssertOK := d.tables[string(tableName)].(map[string]interface{})
if !mapAssertOK {
d.tables[string(tableName)] = make(map[string]interface{})
myTable = d.tables[string(tableName)].(map[string]interface{}) //nolint:forcetypeassert
@ -334,7 +336,7 @@ func trimTest(data []byte) (trimmed []byte) {
func UnmarshalTOML(data []byte, v interface{}) error {
var err error
if data, err = unicode.UTF8.NewDecoder().Bytes(data); err != nil {
return err
return fmt.Errorf("unicode decode failure: %w", err)
}
if !bytes.Contains(data, []byte("[")) {
@ -360,6 +362,7 @@ func UnmarshalTOML(data []byte, v interface{}) error {
if ref.Elem().Kind() != reflect.Struct {
return fmt.Errorf("%w: non-struct", ErrBadTarget)
}
data = bytes.ReplaceAll(data, []byte("\r"), []byte(""))
return newDecoder(data, v).start()

View File

@ -118,7 +118,7 @@ func handleBottomLevelField(field reflect.StructField, ref reflect.Value, buf *p
_, _ = buf.WriteString(field.Tag.Get("toml"))
_, _ = buf.WriteString(" = ")
//goland:noinspection GoSwitchMissingCasesForIotaConsts
switch ref.Kind() {
switch ref.Kind() { //nolint:exhaustive
case reflect.String:
if err := handleString(ref.String(), buf); err != nil {
return err