Skip to content

Commit

Permalink
improve error message on cue load
Browse files Browse the repository at this point in the history
  • Loading branch information
ross96D committed Sep 17, 2024
1 parent e6bd848 commit d2dc1e2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions share/configuration/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit d2dc1e2

Please sign in to comment.