Skip to content

Commit

Permalink
Merge pull request #421 from nicks/nicks/errors
Browse files Browse the repository at this point in the history
improve dotenv error messages
  • Loading branch information
glours authored Jul 10, 2023
2 parents 87ef292 + e5712ff commit 46dcfae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dotenv/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ loop:
}

return "", "", inherited, fmt.Errorf(
`line %d: unexpected character %q in variable name`,
p.line, string(rune))
`line %d: unexpected character %q in variable name %q`,
p.line, string(rune), strings.Split(src, "\n")[0])
}
}

Expand Down
6 changes: 6 additions & 0 deletions dotenv/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ func TestParseBytes(t *testing.T) {
assert.Equal(t, value, out[key])
}
}

func TestParseVariable(t *testing.T) {
err := newParser().parse("%!(EXTRA string)=foo", map[string]string{}, nil)
assert.Error(t, err, "line 1: unexpected character \"%\" in variable name \"%!(EXTRA string)=foo\"")

}
2 changes: 1 addition & 1 deletion types/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func (p Project) ResolveServicesEnvironment(discardEnvFiles bool) error {

fileVars, err := dotenv.ParseWithLookup(bytes.NewBuffer(b), resolve)
if err != nil {
return err
return errors.Wrapf(err, "failed to read %s", envFile)
}
environment.OverrideBy(Mapping(fileVars).ToMappingWithEquals())
}
Expand Down

0 comments on commit 46dcfae

Please sign in to comment.