From dde2258f6919afe59b5675cfcf224c56c91391f1 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Mon, 10 Jun 2024 18:02:47 +0200 Subject: [PATCH] update to latest sconf, for improved error messages for mixed tab/space indenting in config files based on chat with niklas/broitzer --- go.mod | 2 +- go.sum | 4 ++-- vendor/github.com/mjl-/sconf/parse.go | 26 ++++++++++++++++++-------- vendor/modules.txt | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 54cf64b..196270b 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/mjl-/adns v0.0.0-20240509092456-2dc8715bf4af github.com/mjl-/autocert v0.0.0-20231214125928-31b7400acb05 github.com/mjl-/bstore v0.0.6 - github.com/mjl-/sconf v0.0.6 + github.com/mjl-/sconf v0.0.7 github.com/mjl-/sherpa v0.6.7 github.com/mjl-/sherpadoc v0.0.16 github.com/mjl-/sherpaprom v0.0.2 diff --git a/go.sum b/go.sum index 5d0624a..1241af0 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.6 h1:ntlu9MkfCkpm2XfBY4+Ws4KK9YzXzewr3+lCueFB+9c= github.com/mjl-/bstore v0.0.6/go.mod h1:/cD25FNBaDfvL/plFRxI3Ba3E+wcB0XVOS8nJDqndg0= -github.com/mjl-/sconf v0.0.6 h1:5Dt58488ZOoVx680zgK2K3vUrokLsp5mXDUACrJlrUc= -github.com/mjl-/sconf v0.0.6/go.mod h1:uF8OdWtLT8La3i4ln176i1pB0ps9pXGCaABEU55ZkE0= +github.com/mjl-/sconf v0.0.7 h1:bdBcSFZCDFMm/UdBsgNCsjkYmKrSgYwp7rAOoufwHe4= +github.com/mjl-/sconf v0.0.7/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 4f7c8dc..10f342d 100644 --- a/vendor/github.com/mjl-/sconf/parse.go +++ b/vendor/github.com/mjl-/sconf/parse.go @@ -225,20 +225,24 @@ func (p *parser) parseStruct0(v reflect.Value) { var more string if strings.TrimSpace(s) == "" { more = " (perhaps stray whitespace)" + } else if strings.HasPrefix(l[0], " ") { + more = " (perhaps mixed tab/space indenting)" } - p.stop(fmt.Sprintf("missing colon for key/value on non-empty line %q%s", origs, more)) + p.stop(fmt.Sprintf("missing colon for struct key/value on non-empty line %q%s", origs, more)) } k := l[0] if k == "" { - p.stop("empty key") + p.stop("empty key in struct") + } else if strings.HasPrefix(k, " ") { + p.stop("key in struct starting with space (perhaps mixed tab/space indenting)") } if _, ok := seen[k]; ok { - p.stop("duplicate key") + p.stop("duplicate key in struct") } seen[k] = struct{}{} s = l[1] if s != "" && !strings.HasPrefix(s, " ") { - p.stop("missing space after colon") + p.stop("missing space after colon in struct") } if s != "" { s = s[1:] @@ -288,20 +292,26 @@ func (p *parser) parseMap0(v reflect.Value) { var more string if strings.TrimSpace(s) == "" { more = " (perhaps stray whitespace)" + } else if strings.HasPrefix(l[0], " ") { + more = " (perhaps mixed tab/space indenting)" } - p.stop(fmt.Sprintf("missing colon for key/value on non-empty line %q%s", origs, more)) + p.stop(fmt.Sprintf("missing colon for map key/value on non-empty line %q%s", origs, more)) } k := l[0] if k == "" { - p.stop("empty key") + p.stop("empty key in map") } if _, ok := seen[k]; ok { - p.stop("duplicate key") + p.stop("duplicate key in map") } seen[k] = struct{}{} s = l[1] if s != "" && !strings.HasPrefix(s, " ") { - p.stop("missing space after colon") + var more string + if strings.HasPrefix(k, " ") { + more = " (key starts with space, perhaps mixed tab/space indenting)" + } + p.stop("missing space after colon in map" + more) } if s != "" { s = s[1:] diff --git a/vendor/modules.txt b/vendor/modules.txt index c11b323..5280e9c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -19,7 +19,7 @@ github.com/mjl-/autocert # github.com/mjl-/bstore v0.0.6 ## explicit; go 1.19 github.com/mjl-/bstore -# github.com/mjl-/sconf v0.0.6 +# github.com/mjl-/sconf v0.0.7 ## explicit; go 1.12 github.com/mjl-/sconf # github.com/mjl-/sherpa v0.6.7