-
Notifications
You must be signed in to change notification settings - Fork 54
/
errors.go
58 lines (48 loc) · 1.11 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package render
import (
"fmt"
"github.com/osteele/liquid/parser"
)
// An Error is a rendering error during template rendering.
type Error interface {
Filename() string
LineNumber() int
Cause() error
Error() string
}
type renderError struct {
parser.SourceLoc
context string
message string
cause error
}
func (e *renderError) Cause() error {
return e.cause
}
func (e *renderError) Filename() string {
return e.Pathname
}
func (e *renderError) LineNumber() int {
return e.LineNo
}
func (e *renderError) Error() string {
locative := " in " + e.context
if e.Pathname != "" {
locative = " in " + e.Pathname
}
return fmt.Sprintf("Liquid exception: Liquid syntax error (line %d): %s%s", e.LineNo, e.message, locative)
}
func renderErrorf(loc parser.SourceLoc, context, format string, a ...interface{}) *renderError {
return &renderError{loc, context, fmt.Sprintf(format, a...), nil}
}
func wrapRenderError(err error, n Node) Error {
if err == nil {
return nil
}
if e, ok := err.(Error); ok {
return e
}
re := renderErrorf(n.SourceLocation(), n.SourceText(), "%s", err)
re.cause = err
return re
}