Skip to content

Commit

Permalink
refactor: report the full file path in errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Oct 1, 2020
1 parent 8a5bc68 commit f72e351
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core/error.go
Expand Up @@ -114,15 +114,15 @@ func NewE100(context string, err error) error {
// parsable location information on their last line of the form:
//
// <path>:<line>:<start>:<end>
func NewE201(msg, value, file string, finder errorCondition) error {
func NewE201(msg, value, path string, finder errorCondition) error {
var sb bytes.Buffer

f, err := ioutil.ReadFile(file)
f, err := ioutil.ReadFile(path)
if err != nil {
return NewE100("NewE201/ReadFile", err)
}

lexer := lexers.Match(file)
lexer := lexers.Match(path)
err = quick.Highlight(
&sb,
string(f),
Expand All @@ -139,9 +139,15 @@ func NewE201(msg, value, file string, finder errorCondition) error {
return NewE100("NewE201/annotate", err)
}

title := fmt.Sprintf(
"Invalid value provided [%s:%d:%d]:",
path,
ctx.line,
ctx.span[0])

return NewError(
"E201",
fmt.Sprintf("Invalid value provided [%d:%d]:", ctx.line, ctx.span[0]),
title,
fmt.Sprintf("%s\n%s", ctx.content, msg))
}

Expand Down

0 comments on commit f72e351

Please sign in to comment.