Skip to content

Commit 05da118

Browse files
committed
Check return value of the Set function
1 parent c00b05f commit 05da118

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

main.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ func main() {
6565

6666
// Provide the Value helper to the JS code to make it easier to create
6767
// new values inside v1.Struct.
68-
pluginInstance.Impl.VM.Set("Value", pluginInstance.Impl.VM.ToValue(v1.NewValue))
68+
if err := pluginInstance.Impl.VM.Set("Value", pluginInstance.Impl.VM.ToValue(v1.NewValue)); err != nil {
69+
logger.Error("Failed to set Value helper function", "error", err)
70+
return
71+
}
6972

7073
if cfg := cast.ToStringMap(plugin.PluginConfig["config"]); cfg != nil {
7174
config := metrics.NewMetricsConfig(cfg)
@@ -92,17 +95,28 @@ func main() {
9295
pluginInstance.Impl.RegisterFunctions(maps.Keys(plugin.Hooks))
9396

9497
// Register helper functions.
95-
pluginInstance.Impl.VM.Set("btoa", func(call goja.FunctionCall) goja.Value {
98+
if err := pluginInstance.Impl.VM.Set("btoa", func(call goja.FunctionCall) goja.Value {
9699
return pluginInstance.Impl.VM.ToValue(base64.RawStdEncoding.EncodeToString([]byte(call.Arguments[0].String())))
97-
})
98-
pluginInstance.Impl.VM.Set("atob", func(call goja.FunctionCall) goja.Value {
100+
}); err != nil {
101+
logger.Error("Failed to set btoa helper function", "error", err)
102+
return
103+
}
104+
105+
if err := pluginInstance.Impl.VM.Set("atob", func(call goja.FunctionCall) goja.Value {
99106
str, _ := base64.RawStdEncoding.DecodeString(call.Arguments[0].String())
100107
return pluginInstance.Impl.VM.ToValue(string(str))
101-
})
102-
pluginInstance.Impl.VM.Set("parseSQL", func(call goja.FunctionCall) goja.Value {
108+
}); err != nil {
109+
logger.Error("Failed to set atob helper function", "error", err)
110+
return
111+
}
112+
113+
if err := pluginInstance.Impl.VM.Set("parseSQL", func(call goja.FunctionCall) goja.Value {
103114
qStr, _ := pgQuery.ParseToJSON(call.Arguments[0].String())
104115
return pluginInstance.Impl.VM.ToValue(qStr)
105-
})
116+
}); err != nil {
117+
logger.Error("Failed to set parseSQL helper function", "error", err)
118+
return
119+
}
106120
}
107121

108122
goplugin.Serve(&goplugin.ServeConfig{

0 commit comments

Comments
 (0)