forked from rogchap/v8go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
36 lines (32 loc) · 789 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 v8go
import (
"fmt"
"io"
)
// JSError is an error that is returned if there is are any
// JavaScript exceptions handled in the context. When used with the fmt
// verb `%+v`, will output the JavaScript stack trace, if available.
type JSError struct {
Message string
Location string
StackTrace string
}
func (e *JSError) Error() string {
return e.Message
}
// Format implements the fmt.Formatter interface to provide a custom formatter
// primarily to output the javascript stack trace with %+v
func (e *JSError) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
if s.Flag('+') && e.StackTrace != "" {
io.WriteString(s, e.StackTrace)
return
}
fallthrough
case 's':
io.WriteString(s, e.Message)
case 'q':
fmt.Fprintf(s, "%q", e.Message)
}
}