File tree 3 files changed +37
-1
lines changed
3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
20
20
- Support for compiling a context-dependent UnboundScript which can be run in any context of the isolate it was compiled in.
21
21
- Support for creating a code cache from an UnboundScript which can be used to create an UnboundScript in other isolates
22
22
to run a pre-compiled script in new contexts.
23
+ - Included compile error location in ` %+v ` formatting of JSError
23
24
24
25
### Changed
25
26
- Removed error return value from NewIsolate which never fails
Original file line number Diff line number Diff line change @@ -44,7 +44,15 @@ func (e *JSError) Format(s fmt.State, verb rune) {
44
44
switch verb {
45
45
case 'v' :
46
46
if s .Flag ('+' ) && e .StackTrace != "" {
47
+ // The StackTrace starts with the Message, so only the former needs to be printed
47
48
io .WriteString (s , e .StackTrace )
49
+
50
+ // If it was a compile time error, then there wouldn't be a runtime stack trace,
51
+ // but StackTrace will still include the Message, making them equal. In this case,
52
+ // we want to include the Location where the compilation failed.
53
+ if e .StackTrace == e .Message && e .Location != "" {
54
+ fmt .Fprintf (s , " (at %s)" , e .Location )
55
+ }
48
56
return
49
57
}
50
58
fallthrough
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import (
11
11
v8 "rogchap.com/v8go"
12
12
)
13
13
14
- func TestErrorFormatting (t * testing.T ) {
14
+ func TestJSErrorFormat (t * testing.T ) {
15
15
t .Parallel ()
16
16
tests := [... ]struct {
17
17
name string
@@ -90,3 +90,30 @@ func TestJSErrorOutput(t *testing.T) {
90
90
t .Errorf ("unexpected error stack trace: %q" , e .StackTrace )
91
91
}
92
92
}
93
+
94
+ func TestJSErrorFormat_forSyntaxError (t * testing.T ) {
95
+ t .Parallel ()
96
+ iso := v8 .NewIsolate ()
97
+ defer iso .Dispose ()
98
+ ctx := v8 .NewContext (iso )
99
+ defer ctx .Close ()
100
+
101
+ script := `
102
+ let x = 1;
103
+ let y = x + ;
104
+ let z = x + z;
105
+ `
106
+ _ , err := ctx .RunScript (script , "xyz.js" )
107
+ jsErr := err .(* v8.JSError )
108
+ if jsErr .StackTrace != jsErr .Message {
109
+ t .Errorf ("unexpected StackTrace %q not equal to Message %q" , jsErr .StackTrace , jsErr .Message )
110
+ }
111
+ if jsErr .Location == "" {
112
+ t .Errorf ("missing Location" )
113
+ }
114
+
115
+ msg := fmt .Sprintf ("%+v" , err )
116
+ if msg != "SyntaxError: Unexpected token ';' (at xyz.js:3:15)" {
117
+ t .Errorf ("unexpected verbose error message: %q" , msg )
118
+ }
119
+ }
You can’t perform that action at this time.
0 commit comments