Skip to content

Commit 76d4f7f

Browse files
committed
Return error instead of sending event
It is already broadcasted by the caller.
1 parent 49bfbc5 commit 76d4f7f

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

internal/update/apt/service.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,15 @@ func (s *Service) UpgradePackages(ctx context.Context, names []string, eventCB f
9696
stream := runUpgradeCommand(ctx, names)
9797
for line, err := range stream {
9898
if err != nil {
99-
eventCB(update.NewErrorEvent(fmt.Errorf("error running upgrade command: %w", err)))
100-
return nil
99+
return fmt.Errorf("error running upgrade command: %w", err)
101100
}
102101
eventCB(update.NewDataEvent(update.UpgradeLineEvent, line))
103102
}
104103

105104
eventCB(update.NewDataEvent(update.StartEvent, "apt cleaning cache is starting"))
106105
for line, err := range runAptCleanCommand(ctx) {
107106
if err != nil {
108-
eventCB(update.NewErrorEvent(fmt.Errorf("error running apt clean command: %w", err)))
109-
return nil
107+
return fmt.Errorf("error running apt clean command: %w", err)
110108
}
111109
eventCB(update.NewDataEvent(update.UpgradeLineEvent, line))
112110
}
@@ -131,8 +129,7 @@ func (s *Service) UpgradePackages(ctx context.Context, names []string, eventCB f
131129
streamDocker := pullDockerImages(ctx)
132130
for line, err := range streamDocker {
133131
if err != nil {
134-
eventCB(update.NewErrorEvent(fmt.Errorf("error pulling docker images: %w", err)))
135-
return nil
132+
return fmt.Errorf("error pulling docker images: %w", err)
136133
}
137134
eventCB(update.NewDataEvent(update.UpgradeLineEvent, line))
138135
}

internal/update/arduino/arduino.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,12 @@ func (a *ArduinoPlatformUpdater) UpgradePackages(ctx context.Context, names []st
158158
srv := commands.NewArduinoCoreServer()
159159

160160
if err := setConfig(ctx, srv); err != nil {
161-
eventCB(update.NewErrorEvent(fmt.Errorf("error setting config: %w", err)))
162-
return nil
161+
return fmt.Errorf("error setting config: %w", err)
163162
}
164163

165164
var inst *rpc.Instance
166165
if resp, err := srv.Create(ctx, &rpc.CreateRequest{}); err != nil {
167-
eventCB(update.NewErrorEvent(fmt.Errorf("error creating arduino-cli instance: %w", err)))
168-
return nil
166+
return fmt.Errorf("error creating arduino-cli instance: %w", err)
169167
} else {
170168
inst = resp.GetInstance()
171169
}
@@ -180,12 +178,10 @@ func (a *ArduinoPlatformUpdater) UpgradePackages(ctx context.Context, names []st
180178
{
181179
stream, _ := commands.UpdateIndexStreamResponseToCallbackFunction(ctx, downloadProgressCB)
182180
if err := srv.UpdateIndex(&rpc.UpdateIndexRequest{Instance: inst}, stream); err != nil {
183-
eventCB(update.NewErrorEvent(fmt.Errorf("error updating index: %w", err)))
184-
return nil
181+
return fmt.Errorf("error updating index: %w", err)
185182
}
186183
if err := srv.Init(&rpc.InitRequest{Instance: inst}, commands.InitStreamResponseToCallbackFunction(ctx, nil)); err != nil {
187-
eventCB(update.NewErrorEvent(fmt.Errorf("error initializing instance: %w", err)))
188-
return nil
184+
return fmt.Errorf("error initializing instance: %w", err)
189185
}
190186
}
191187

@@ -212,8 +208,7 @@ func (a *ArduinoPlatformUpdater) UpgradePackages(ctx context.Context, names []st
212208

213209
var notFound *cmderrors.PlatformNotFoundError
214210
if !errors.As(err, &notFound) {
215-
eventCB(update.NewErrorEvent(fmt.Errorf("error upgrading platform: %w", err)))
216-
return nil
211+
return fmt.Errorf("error upgrading platform: %w", err)
217212
}
218213
// If the platform is not found, we will try to install it
219214
err := srv.PlatformInstall(
@@ -229,12 +224,10 @@ func (a *ArduinoPlatformUpdater) UpgradePackages(ctx context.Context, names []st
229224
),
230225
)
231226
if err != nil {
232-
eventCB(update.NewErrorEvent(fmt.Errorf("error installing platform: %w", err)))
233-
return nil
227+
return fmt.Errorf("error installing platform: %w", err)
234228
}
235229
} else if respCB().GetPlatform() == nil {
236-
eventCB(update.NewErrorEvent(fmt.Errorf("platform upgrade failed")))
237-
return nil
230+
return fmt.Errorf("platform upgrade failed")
238231
}
239232

240233
cbw := orchestrator.NewCallbackWriter(func(line string) {
@@ -250,8 +243,7 @@ func (a *ArduinoPlatformUpdater) UpgradePackages(ctx context.Context, names []st
250243
commands.BurnBootloaderToServerStreams(ctx, cbw, cbw),
251244
)
252245
if err != nil {
253-
eventCB(update.NewErrorEvent(fmt.Errorf("error burning bootloader: %w", err)))
254-
return nil
246+
return fmt.Errorf("error burning bootloader: %w", err)
255247
}
256248

257249
return nil

0 commit comments

Comments
 (0)