Skip to content

Commit 9ec7630

Browse files
authored
fix(errmsg): should not return debug info of key cell when parsing map value as message (#307)
* fix(errmsg): should not return debug info of key cell when parsing map value as message * fix: error desc kv pairs, the last one wins
1 parent 5200597 commit 9ec7630

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

internal/confgen/table_parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (sp *tableParser) parseVerticalMapField(field *Field, msg protoreflect.Mess
248248
}
249249
valuePresent, err := sp.parseMessage(newMapValue.Message(), rc, newPrefix, newCardPrefix)
250250
if err != nil {
251-
return false, xerrors.WrapKV(err, rc.CellDebugKV(keyColName)...)
251+
return false, err
252252
}
253253
if !keyPresent && !valuePresent {
254254
// key and value are both not present.
@@ -305,7 +305,7 @@ func (sp *tableParser) parseHorizontalMapField(field *Field, msg protoreflect.Me
305305
tempCheckMapValue := reflectMap.NewValue()
306306
valuePresent, err := sp.parseMessage(tempCheckMapValue.Message(), rc, elemPrefix, newCardPrefix)
307307
if err != nil {
308-
return false, xerrors.WrapKV(err, rc.CellDebugKV(keyColName)...)
308+
return false, err
309309
}
310310
if valuePresent {
311311
return false, xerrors.WrapKV(xerrors.E2017(xproto.GetFieldTypeName(field.fd)), rc.CellDebugKV(keyColName)...)

xerrors/desc.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ func NewDesc(err error) *Desc {
9595
fields: map[string]any{},
9696
}
9797

98+
// NOTE: In the splits slice, the latter key-value pairs will overwrite
99+
// earlier ones if they have the same key, so the last one wins.
98100
splits := strings.Split(err.Error(), "|")
99101
for _, s := range splits {
100102
kv := strings.SplitN(s, ":", 2)
101103
if len(kv) == 2 {
102104
key, val := strings.Trim(kv[0], " :"), strings.Trim(kv[1], " :")
103-
if key != "" && val != "" {
105+
if key != "" {
104106
desc.setField(key, val)
105107
}
106108
}

0 commit comments

Comments
 (0)