Skip to content

Commit eb61a31

Browse files
committed
Fix unhandled error in goja
1 parent 7a2e9cd commit eb61a31

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

goja.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,22 @@ var pool = sync.Pool{
6666
}
6767

6868
// FormatDartStandalone formats a script without dependencies on external commands
69-
func FormatDartStandalone(script string) (string, error) {
69+
func FormatDartStandalone(script string) (result string, err error) {
70+
defer func() {
71+
e := recover()
72+
73+
if e == nil {
74+
return
75+
}
76+
77+
if e, ok := e.(error); ok {
78+
err = e
79+
return
80+
}
81+
82+
err = fmt.Errorf("%v", e)
83+
}()
84+
7085
vm := pool.Get().(*goja.Runtime)
7186
defer pool.Put(vm)
7287

@@ -77,7 +92,7 @@ func FormatDartStandalone(script string) (string, error) {
7792
}
7893

7994
var fn func(string) string
80-
err := vm.ExportTo(dartFormat, &fn)
95+
err = vm.ExportTo(dartFormat, &fn)
8196
if err != nil {
8297
return "", fmt.Errorf("failed to execute dart_style formatter: %w", err)
8398
}

0 commit comments

Comments
 (0)