-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.go
36 lines (30 loc) · 931 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package awqlparse
import (
"fmt"
"strings"
)
// ParserError represents an error of parse.
type ParserError struct {
s string
a interface{}
}
// NewParserError returns an error with the parsing.
func NewParserError(text string) error {
return &ParserError{s: formatError(text)}
}
// NewXParserError returns an error with the parsing with more information about it.
func NewXParserError(text string, arg interface{}) error {
return &ParserError{s: formatError(text), a: arg}
}
// Error returns the message of the parse error.
func (e *ParserError) Error() string {
if e.a != nil {
return fmt.Sprintf("ParserError.%v (%v)", e.s, e.a)
}
return fmt.Sprintf("ParserError.%v", e.s)
}
// formatError returns a string in upper case with underscore instead of space.
// As the Adwords API outputs its errors.
func formatError(s string) string {
return strings.Replace(strings.ToUpper(strings.TrimSpace(s)), " ", "_", -1)
}