Skip to content

Commit 965a473

Browse files
nianyushItxaka
authored andcommitted
fix: dont try to unmarshal into JSON if data is empty (#996)
(cherry picked from commit cb5cb98)
1 parent 8a02d4b commit 965a473

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

internal/agent/TUIcustomizationPage.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ func runCustomizationPlugins() ([]YAMLPrompt, error) {
3535
var r []YAMLPrompt
3636

3737
bus.Manager.Response(sdk.EventInteractiveInstall, func(p *pluggable.Plugin, resp *pluggable.EventResponse) {
38-
err := json.Unmarshal([]byte(resp.Data), &r)
39-
if err != nil {
38+
if resp.Data == "" {
39+
return
40+
}
41+
if err := json.Unmarshal([]byte(resp.Data), &r); err != nil {
4042
fmt.Println(err)
4143
}
4244
})

internal/agent/install.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ func Install(sourceImgURL string, dir ...string) error {
9696
})
9797

9898
bus.Manager.Response(events.EventInstall, func(p *pluggable.Plugin, resp *pluggable.EventResponse) {
99+
if resp.Data == "" {
100+
return
101+
}
99102
err := json.Unmarshal([]byte(resp.Data), &r)
100103
if err != nil {
101104
fmt.Println(err)

internal/agent/reset.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ func sharedReset(reboot, unattended, resetOem bool, dir ...string) (c *config.Co
139139
// This gets the options from an event that can be sent by anyone.
140140
// This should override the default config as it's much more dynamic
141141
bus.Manager.Response(sdk.EventBeforeReset, func(p *pluggable.Plugin, r *pluggable.EventResponse) {
142+
if r.Data == "" {
143+
return
144+
}
142145
err := json.Unmarshal([]byte(r.Data), &optionsFromEvent)
143146
if err != nil {
144147
fmt.Println(err)

0 commit comments

Comments
 (0)