@@ -29,11 +29,28 @@ func main() {
29
29
<- done
30
30
}
31
31
32
+ type previewOutput struct {
33
+ Output preview.Output `json:"output"`
34
+ Diags []types.FriendlyDiagnostic `json:"diags"`
35
+ }
36
+
32
37
func tfpreview (this js.Value , p []js.Value ) any {
33
38
defer func () {
39
+ // Return a panic as a diagnostic if one occurs.
34
40
if r := recover (); r != nil {
35
- // Panic happened, do something
36
- return fmt .Sprintf ("Something went wrong: %v" , r )
41
+ data , _ := json .Marshal (previewOutput {
42
+ Output : preview.Output {},
43
+ Diags : []types.FriendlyDiagnostic {
44
+ {
45
+ Severity : types .DiagnosticSeverityError ,
46
+ Summary : "A panic occurred" ,
47
+ Detail : fmt .Sprintf ("%v" , r ),
48
+ Extra : types.DiagnosticExtra {},
49
+ },
50
+ },
51
+ })
52
+
53
+ return js .ValueOf (string (data ))
37
54
}
38
55
}()
39
56
@@ -53,9 +70,9 @@ func tfpreview(this js.Value, p []js.Value) any {
53
70
Logger : logger ,
54
71
}, tf )
55
72
56
- data , _ := json .Marshal (map [ string ] any {
57
- "output" : output ,
58
- "diags" : diags ,
73
+ data , _ := json .Marshal (previewOutput {
74
+ Output : output ,
75
+ Diags : diags ,
59
76
})
60
77
61
78
return js .ValueOf (string (data ))
0 commit comments