mirror of
https://github.com/cloudflare/redoctober.git
synced 2026-01-05 13:07:10 +00:00
Write better error messages.
This commit is contained in:
committed by
Brendan McMillion
parent
9e514e902a
commit
4c161e343c
@@ -26,7 +26,7 @@ func StringToFormatted(f string) (out Formatted, err error) {
|
||||
// Staging stack is empty on initialization and should have exactly 1 built
|
||||
// threshold gate at the end of the string.
|
||||
if f[0] != '(' || f[len(f)-1] != ')' {
|
||||
return out, errors.New("Invalid string--wrong format.")
|
||||
return out, errors.New("Invalid string: Needs to begin and end with parentheses.")
|
||||
}
|
||||
|
||||
getNext := func(f string) (string, string) { // f -> (next, rest)
|
||||
@@ -87,7 +87,7 @@ func StringToFormatted(f string) (out Formatted, err error) {
|
||||
if len(f) == 0 {
|
||||
return built, nil
|
||||
}
|
||||
return built, errors.New("Invalid string--terminated early.")
|
||||
return built, errors.New("Invalid string: Can't parse anymore, but there's still data. Too many closing parentheses or too few opening parentheses?")
|
||||
}
|
||||
|
||||
staging.Front().Value.(*list.List).PushBack(built)
|
||||
@@ -102,7 +102,7 @@ func StringToFormatted(f string) (out Formatted, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
return out, errors.New("Invalid string--never terminated.")
|
||||
return out, errors.New("Invalid string: Not finished parsing, but out of data. Too many opening parentheses or too few closing parentheses?")
|
||||
}
|
||||
|
||||
func (f Formatted) String() string {
|
||||
|
||||
@@ -97,7 +97,7 @@ func StringToRaw(r string) (out Raw, err error) {
|
||||
case ")":
|
||||
top := staging.Remove(staging.Front()).([2]*list.List)
|
||||
if top[0].Len() != (top[1].Len() + 1) {
|
||||
return out, errors.New("Stacks are invalid size.")
|
||||
return out, errors.New("Invalid string: There needs to be an operator (& or |) for every pair of operands.")
|
||||
}
|
||||
|
||||
for typ := NodeAnd; typ <= NodeOr; typ++ {
|
||||
@@ -128,14 +128,14 @@ func StringToRaw(r string) (out Raw, err error) {
|
||||
}
|
||||
|
||||
if top[0].Len() != 1 || top[1].Len() != 0 {
|
||||
return out, errors.New("Invalid expression--couldn't evaluate.")
|
||||
return out, errors.New("Invalid string: Couldn't evaluate all of the operators.")
|
||||
}
|
||||
|
||||
if staging.Len() == 0 {
|
||||
if len(r) == 0 {
|
||||
return top[0].Front().Value.(Raw), nil
|
||||
}
|
||||
return out, errors.New("Invalid string--terminated early.")
|
||||
return out, errors.New("Invalid string: Can't parse anymore, but there's still data. Too many closing parentheses or too few opening parentheses?")
|
||||
}
|
||||
staging.Front().Value.([2]*list.List)[0].PushBack(top[0].Front().Value)
|
||||
|
||||
@@ -153,7 +153,7 @@ func StringToRaw(r string) (out Raw, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
return out, errors.New("Invalid string--never terminated.")
|
||||
return out, errors.New("Invalid string: Not finished parsing, but out of data. Too many opening parentheses or too few closing parentheses?")
|
||||
}
|
||||
|
||||
func (r Raw) String() string {
|
||||
|
||||
Reference in New Issue
Block a user