File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 7
7
"encoding/json"
8
8
"fmt"
9
9
"io/fs"
10
+ "log/slog"
10
11
"path/filepath"
11
12
"syscall/js"
12
13
@@ -29,22 +30,34 @@ func main() {
29
30
}
30
31
31
32
func tfpreview (this js.Value , p []js.Value ) any {
33
+ defer func () {
34
+ if r := recover (); r != nil {
35
+ // Panic happened, do something
36
+ return fmt .Sprintf ("Something went wrong: %v" , r )
37
+ }
38
+ }()
39
+
32
40
tf , err := fileTreeFS (p [0 ])
33
41
if err != nil {
34
42
return err
35
43
}
36
44
45
+ // TODO: Capture the logger into a bytes.Buffer, and return this
46
+ // as a string in the output?
47
+ logger := slog .New (slog .DiscardHandler )
37
48
output , diags := preview .Preview (context .Background (), preview.Input {
38
49
PlanJSONPath : "" ,
39
50
PlanJSON : nil ,
40
51
ParameterValues : nil ,
41
52
Owner : types.WorkspaceOwner {},
53
+ Logger : logger ,
42
54
}, tf )
43
55
44
56
data , _ := json .Marshal (map [string ]any {
45
57
"output" : output ,
46
58
"diags" : diags ,
47
59
})
60
+
48
61
return js .ValueOf (string (data ))
49
62
}
50
63
You can’t perform that action at this time.
0 commit comments