Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit 4cffecb

Browse files
committed
expr: don't panic for user sending bad input
1 parent f48f1b3 commit 4cffecb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

expr/parse.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func ParseMany(targets []string) ([]*expr, error) {
8686
return nil, err
8787
}
8888
if leftover != "" {
89-
panic(fmt.Sprintf("failed to parse %q fully. got leftover %q", target, leftover))
89+
return nil, fmt.Errorf("failed to parse %q fully. got leftover %q", target, leftover)
9090
}
9191
out = append(out, e)
9292
}
@@ -148,6 +148,7 @@ func Parse(e string) (*expr, string, error) {
148148
return &expr{str: name, etype: etName}, e, nil
149149
}
150150

151+
// caller must assure s starts with opening paren
151152
func parseArgList(e string) (string, []*expr, map[string]*expr, string, error) {
152153

153154
var (
@@ -156,7 +157,7 @@ func parseArgList(e string) (string, []*expr, map[string]*expr, string, error) {
156157
)
157158

158159
if e[0] != '(' {
159-
panic("arg list should start with paren")
160+
panic("arg list should start with paren. calling code should have asserted this")
160161
}
161162

162163
ArgString := e[1:]
@@ -301,10 +302,11 @@ FOR:
301302
return s[:i], s[i:]
302303
}
303304

305+
// caller must assure s starts with a single or double quote
304306
func parseString(s string) (string, string, error) {
305307

306308
if s[0] != '\'' && s[0] != '"' {
307-
panic("string should start with open quote")
309+
panic("string should start with open quote. calling code should have asserted this")
308310
}
309311

310312
match := s[0]

0 commit comments

Comments
 (0)