Skip to content

Commit b540046

Browse files
committed
detail error
1 parent 3a4d22a commit b540046

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

modules/templates/vars/vars.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import (
99
"strings"
1010
)
1111

12-
// ErrWrongSyntax represents a wrong syntax with a tempate
12+
// ErrWrongSyntax represents a syntax error within a template
1313
type ErrWrongSyntax struct {
1414
Template string
15+
Reason string
1516
}
1617

1718
func (err ErrWrongSyntax) Error() string {
18-
return fmt.Sprintf("Wrong syntax found in %s", err.Template)
19+
return fmt.Sprintf("Wrong syntax found in %s: %s", err.Template, err.Reason)
1920
}
2021

2122
// IsErrWrongSyntax returns true if the error is ErrWrongSyntax
@@ -52,18 +53,21 @@ func Expand(template string, match map[string]string, subs ...string) (string, e
5253
if keyStartPos > -1 {
5354
return "", ErrWrongSyntax{
5455
Template: template,
56+
Reason: "\"{\" is not allowed to occur again before closing the variable",
5557
}
5658
}
5759
keyStartPos = i
5860
case c == '}':
5961
if keyStartPos == -1 {
6062
return "", ErrWrongSyntax{
6163
Template: template,
64+
Reason: "\"}\" can only occur after an opening \"{\"",
6265
}
6366
}
6467
if i-keyStartPos <= 1 {
6568
return "", ErrWrongSyntax{
6669
Template: template,
70+
Reason: "the empty variable (\"{}\") is not allowed",
6771
}
6872
}
6973

0 commit comments

Comments
 (0)