update to latest sconf, which now gives more helpful error messages about some invalid config lines, like one with only whitespace

from arnt & friend, thanks for reporting!
This commit is contained in:
Mechiel Lukkien
2024-03-27 10:08:15 +01:00
parent 0262f4621e
commit 6516a27689
4 changed files with 25 additions and 13 deletions

View File

@ -218,11 +218,15 @@ func (p *parser) parseStruct0(v reflect.Value) {
var zeroValue reflect.Value
t := v.Type()
for p.next() {
s := p.string()
s = s[len(p.prefix):]
origs := p.string()
s := origs[len(p.prefix):]
l := strings.SplitN(s, ":", 2)
if len(l) != 2 {
p.stop("missing key: value")
var more string
if strings.TrimSpace(s) == "" {
more = " (perhaps stray whitespace)"
}
p.stop(fmt.Sprintf("missing colon for key/value on non-empty line %q%s", origs, more))
}
k := l[0]
if k == "" {
@ -234,7 +238,7 @@ func (p *parser) parseStruct0(v reflect.Value) {
seen[k] = struct{}{}
s = l[1]
if s != "" && !strings.HasPrefix(s, " ") {
p.stop("no space after colon")
p.stop("missing space after colon")
}
if s != "" {
s = s[1:]
@ -243,7 +247,11 @@ func (p *parser) parseStruct0(v reflect.Value) {
vv := v.FieldByName(k)
if vv == zeroValue {
p.stop(fmt.Sprintf("unknown key %q", k))
var more string
if strings.TrimSpace(k) != k {
more = " (perhaps stray whitespace in key)"
}
p.stop(fmt.Sprintf("unknown key %q%s", k, more))
}
if ft, _ := t.FieldByName(k); !ft.IsExported() || isIgnore(ft.Tag.Get("sconf")) {
p.stop(fmt.Sprintf("unknown key %q (has ignore tag or not exported)", k))
@ -273,11 +281,15 @@ func (p *parser) parseMap0(v reflect.Value) {
seen := map[string]struct{}{}
t := v.Type()
for p.next() {
s := p.string()
s = s[len(p.prefix):]
origs := p.string()
s := origs[len(p.prefix):]
l := strings.SplitN(s, ":", 2)
if len(l) != 2 {
p.stop("missing key: value")
var more string
if strings.TrimSpace(s) == "" {
more = " (perhaps stray whitespace)"
}
p.stop(fmt.Sprintf("missing colon for key/value on non-empty line %q%s", origs, more))
}
k := l[0]
if k == "" {
@ -289,7 +301,7 @@ func (p *parser) parseMap0(v reflect.Value) {
seen[k] = struct{}{}
s = l[1]
if s != "" && !strings.HasPrefix(s, " ") {
p.stop("no space after colon")
p.stop("missing space after colon")
}
if s != "" {
s = s[1:]