stash
stash copied to clipboard
[Bug Report] hookContext has invalid casing for JS plugin
Describe the bug It's not very clear what is the format for a JS plugin input. Should it follow the JSON casing or should it follow the object casing?
The object in question: https://github.com/WithoutPants/stash/blob/f64d5436dba6362116163c45d28688b0327cbbfd/pkg/plugin/common/msg.go#L113-L120
// HookContext is passed as a PluginArgValue and indicates what hook triggered
// this plugin task.
type HookContext struct {
ID int `json:"id,omitempty"`
Type string `json:"type"`
Input interface{} `json:"input"`
InputFields []string `json:"inputFields,omitempty"`
}
Note Type vs type.
When trying to get the type in JS this fails:
input.Args.hookContext.type
A simple test JS plugin that reacts on hooks:
log.Info(JSON.stringify(input.Args));
log.Info(input.Args);
log.Info(Object.getOwnPropertyNames(input.Args));
log.Info(input.Args.hasOwnProperty('hookContext'));
log.Info(Object.getOwnPropertyNames(input.Args.hookContext));
log.Info(input.Args.hookContext.hasOwnProperty('type'));
log.Info(input.Args.hookContext.hasOwnProperty('Type'));
return { Output: 'ok' };
results in these log entries (I've reversed the order to match the code):
Info [Plugin] {"hookContext":{"ID":123,"Type":"Scene.Create.Post","Input":null,"InputFields":[]}}
Info [Plugin] {"hookContext":{"id":123,"type":"Scene.Create.Post","input":null}}
Info [Plugin] hookContext
Info [Plugin] true
Info [Plugin] ID,Type,Input,InputFields
Info [Plugin] false
Info [Plugin] true
Note the difference in casing when using stringify.
This may have been introduced in #4631