From d2dc1e2a5df7caf64689db724a08f3c57915c12c Mon Sep 17 00:00:00 2001 From: ross96D Date: Tue, 17 Sep 2024 00:36:46 -0400 Subject: [PATCH] improve error message on cue load --- share/configuration/load.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/share/configuration/load.go b/share/configuration/load.go index b726e8c..6bc90d1 100644 --- a/share/configuration/load.go +++ b/share/configuration/load.go @@ -4,16 +4,33 @@ import ( "bytes" _ "embed" "errors" + "fmt" "io" "os" "path/filepath" "runtime" + "strings" "cuelang.org/go/cue/cuecontext" + cuerrors "cuelang.org/go/cue/errors" "cuelang.org/go/cue/load" ) +type cuerror struct{ error cuerrors.Error } + +func (err cuerror) Error() string { + result := strings.Builder{} + position := err.error.Position().Position() + if position.IsValid() { + result.WriteString(position.String()) + result.WriteString(" ") + } + format, args := err.error.Msg() + result.WriteString(fmt.Sprintf(format, args...)) + return result.String() +} + var cacheDir string var definitionPath string var configPath string @@ -78,6 +95,9 @@ func _load() (c Configuration, err error) { var config Configuration err = v[0].Decode(&config) + if err, ok := err.(cuerrors.Error); ok && err != nil { + return config, cuerror{err} + } return config, err }