fix: dont try to unmarshal into JSON if data is empty (#996)

This commit is contained in:
Nianyu Shen
2025-10-15 00:11:59 -07:00
committed by GitHub
parent ce56d0c2e3
commit cb5cb9848c
3 changed files with 10 additions and 2 deletions

View File

@@ -35,8 +35,10 @@ func runCustomizationPlugins() ([]YAMLPrompt, error) {
var r []YAMLPrompt
bus.Manager.Response(sdk.EventInteractiveInstall, func(p *pluggable.Plugin, resp *pluggable.EventResponse) {
err := json.Unmarshal([]byte(resp.Data), &r)
if err != nil {
if resp.Data == "" {
return
}
if err := json.Unmarshal([]byte(resp.Data), &r); err != nil {
fmt.Println(err)
}
})

View File

@@ -96,6 +96,9 @@ func Install(sourceImgURL string, dir ...string) error {
})
bus.Manager.Response(events.EventInstall, func(p *pluggable.Plugin, resp *pluggable.EventResponse) {
if resp.Data == "" {
return
}
err := json.Unmarshal([]byte(resp.Data), &r)
if err != nil {
fmt.Println(err)

View File

@@ -139,6 +139,9 @@ func sharedReset(reboot, unattended, resetOem bool, dir ...string) (c *config.Co
// This gets the options from an event that can be sent by anyone.
// This should override the default config as it's much more dynamic
bus.Manager.Response(sdk.EventBeforeReset, func(p *pluggable.Plugin, r *pluggable.EventResponse) {
if r.Data == "" {
return
}
err := json.Unmarshal([]byte(r.Data), &optionsFromEvent)
if err != nil {
fmt.Println(err)