From 6516a27689cbbacdf9653238500a9857eadcc32a Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien <mechiel@ueber.net> Date: Wed, 27 Mar 2024 10:08:15 +0100 Subject: [PATCH] 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! --- go.mod | 2 +- go.sum | 4 ++-- vendor/github.com/mjl-/sconf/parse.go | 30 +++++++++++++++++++-------- vendor/modules.txt | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index eed91dd..f9a7915 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/mjl-/adns v0.0.0-20240309142737-2a1aacf346dc github.com/mjl-/autocert v0.0.0-20231214125928-31b7400acb05 github.com/mjl-/bstore v0.0.4 - github.com/mjl-/sconf v0.0.5 + github.com/mjl-/sconf v0.0.6 github.com/mjl-/sherpa v0.6.7 github.com/mjl-/sherpadoc v0.0.12 github.com/mjl-/sherpaprom v0.0.2 diff --git a/go.sum b/go.sum index ee2505c..e28beac 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/mjl-/autocert v0.0.0-20231214125928-31b7400acb05 h1:s6ay4bh4tmpPLdxjy github.com/mjl-/autocert v0.0.0-20231214125928-31b7400acb05/go.mod h1:taMFU86abMxKLPV4Bynhv8enbYmS67b8LG80qZv2Qus= github.com/mjl-/bstore v0.0.4 h1:q+R1oAr8+E9yf9q+zxkVjQ18VFqD/E9KmGVoe4FIOBA= github.com/mjl-/bstore v0.0.4/go.mod h1:/cD25FNBaDfvL/plFRxI3Ba3E+wcB0XVOS8nJDqndg0= -github.com/mjl-/sconf v0.0.5 h1:4CMUTENpSnaeP2g6RKtrs8udTxnJgjX2MCCovxGId6s= -github.com/mjl-/sconf v0.0.5/go.mod h1:uF8OdWtLT8La3i4ln176i1pB0ps9pXGCaABEU55ZkE0= +github.com/mjl-/sconf v0.0.6 h1:5Dt58488ZOoVx680zgK2K3vUrokLsp5mXDUACrJlrUc= +github.com/mjl-/sconf v0.0.6/go.mod h1:uF8OdWtLT8La3i4ln176i1pB0ps9pXGCaABEU55ZkE0= github.com/mjl-/sherpa v0.6.7 h1:C5F8XQdV5nCuS4fvB+ye/ziUQrajEhOoj/t2w5T14BY= github.com/mjl-/sherpa v0.6.7/go.mod h1:dSpAOdgpwdqQZ72O4n3EHo/tR68eKyan8tYYraUMPNc= github.com/mjl-/sherpadoc v0.0.0-20190505200843-c0a7f43f5f1d/go.mod h1:5khTKxoKKNXcB8bkVUO6GlzC7PFtMmkHq578lPbmnok= diff --git a/vendor/github.com/mjl-/sconf/parse.go b/vendor/github.com/mjl-/sconf/parse.go index a4e765e..4f7c8dc 100644 --- a/vendor/github.com/mjl-/sconf/parse.go +++ b/vendor/github.com/mjl-/sconf/parse.go @@ -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:] diff --git a/vendor/modules.txt b/vendor/modules.txt index c74595e..bea4dd1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -19,7 +19,7 @@ github.com/mjl-/autocert # github.com/mjl-/bstore v0.0.4 ## explicit; go 1.19 github.com/mjl-/bstore -# github.com/mjl-/sconf v0.0.5 +# github.com/mjl-/sconf v0.0.6 ## explicit; go 1.12 github.com/mjl-/sconf # github.com/mjl-/sherpa v0.6.7