Skip to content

Commit e479ddd

Browse files
authored
Merge pull request #4437 from sneugle/error-logging-in-pkg/driver/external
Change error logging from using string formatting to logger.WithError
2 parents 655acbd + 12d6b52 commit e479ddd

File tree

2 files changed

+48
-49
lines changed

2 files changed

+48
-49
lines changed

pkg/driver/external/client/methods.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (d *DriverClient) Validate(ctx context.Context) error {
2424
defer cancel()
2525
_, err := d.DriverSvc.Validate(ctx, &emptypb.Empty{})
2626
if err != nil {
27-
d.logger.Errorf("Validation failed: %v", err)
27+
d.logger.WithError(err).Error("Validation failed")
2828
return err
2929
}
3030

@@ -37,7 +37,7 @@ func (d *DriverClient) Create(ctx context.Context) error {
3737

3838
_, err := d.DriverSvc.Create(ctx, &emptypb.Empty{})
3939
if err != nil {
40-
d.logger.Errorf("Initialization failed: %v", err)
40+
d.logger.WithError(err).Error("Initialization failed")
4141
return err
4242
}
4343

@@ -50,7 +50,7 @@ func (d *DriverClient) CreateDisk(ctx context.Context) error {
5050

5151
_, err := d.DriverSvc.CreateDisk(ctx, &emptypb.Empty{})
5252
if err != nil {
53-
d.logger.Errorf("Disk creation failed: %v", err)
53+
d.logger.WithError(err).Error("Disk creation failed")
5454
return err
5555
}
5656

@@ -66,7 +66,7 @@ func (d *DriverClient) Start(ctx context.Context) (chan error, error) {
6666

6767
stream, err := d.DriverSvc.Start(ctx, &emptypb.Empty{})
6868
if err != nil {
69-
d.logger.Errorf("Failed to start driver instance: %v", err)
69+
d.logger.WithError(err).Error("Failed to start driver instance")
7070
return nil, err
7171
}
7272

@@ -115,7 +115,7 @@ func (d *DriverClient) Stop(ctx context.Context) error {
115115

116116
_, err := d.DriverSvc.Stop(ctx, &emptypb.Empty{})
117117
if err != nil {
118-
d.logger.Errorf("Failed to stop driver instance: %v", err)
118+
d.logger.WithError(err).Error("Failed to stop driver instance")
119119
return err
120120
}
121121

@@ -128,7 +128,7 @@ func (d *DriverClient) Delete(ctx context.Context) error {
128128

129129
_, err := d.DriverSvc.Delete(ctx, &emptypb.Empty{})
130130
if err != nil {
131-
d.logger.Errorf("Failed to delete driver instance: %v", err)
131+
d.logger.WithError(err).Error("Failed to deleted driver instance")
132132
return err
133133
}
134134

@@ -148,7 +148,7 @@ func (d *DriverClient) RunGUI() error {
148148

149149
_, err := d.DriverSvc.RunGUI(ctx, &emptypb.Empty{})
150150
if err != nil {
151-
d.logger.Errorf("Failed to run GUI: %v", err)
151+
d.logger.WithError(err).Error("Failed to run GUI")
152152
return err
153153
}
154154

@@ -163,7 +163,7 @@ func (d *DriverClient) ChangeDisplayPassword(ctx context.Context, password strin
163163
Password: password,
164164
})
165165
if err != nil {
166-
d.logger.Errorf("Failed to change display password: %v", err)
166+
d.logger.WithError(err).Error("Failed to change display password")
167167
return err
168168
}
169169

@@ -176,7 +176,7 @@ func (d *DriverClient) DisplayConnection(ctx context.Context) (string, error) {
176176

177177
resp, err := d.DriverSvc.GetDisplayConnection(ctx, &emptypb.Empty{})
178178
if err != nil {
179-
d.logger.Errorf("Failed to get display connection: %v", err)
179+
d.logger.WithError(err).Error("Failed to get display connection")
180180
return "", err
181181
}
182182

@@ -191,7 +191,7 @@ func (d *DriverClient) CreateSnapshot(ctx context.Context, tag string) error {
191191
Tag: tag,
192192
})
193193
if err != nil {
194-
d.logger.Errorf("Failed to create snapshot: %v", err)
194+
d.logger.WithError(err).Error("Failed to create snapshot")
195195
return err
196196
}
197197

@@ -206,7 +206,7 @@ func (d *DriverClient) ApplySnapshot(ctx context.Context, tag string) error {
206206
Tag: tag,
207207
})
208208
if err != nil {
209-
d.logger.Errorf("Failed to apply snapshot: %v", err)
209+
d.logger.WithError(err).Error("Failed to apply snapshot")
210210
return err
211211
}
212212

@@ -221,7 +221,7 @@ func (d *DriverClient) DeleteSnapshot(ctx context.Context, tag string) error {
221221
Tag: tag,
222222
})
223223
if err != nil {
224-
d.logger.Errorf("Failed to delete snapshot: %v", err)
224+
d.logger.WithError(err).Error("Failed to delete snapshot")
225225
return err
226226
}
227227

@@ -234,7 +234,7 @@ func (d *DriverClient) ListSnapshots(ctx context.Context) (string, error) {
234234

235235
resp, err := d.DriverSvc.ListSnapshots(ctx, &emptypb.Empty{})
236236
if err != nil {
237-
d.logger.Errorf("Failed to list snapshots: %v", err)
237+
d.logger.WithError(err).Error("Failed to list snapshots")
238238
return "", err
239239
}
240240

@@ -250,7 +250,7 @@ func (d *DriverClient) ForwardGuestAgent() bool {
250250

251251
resp, err := d.DriverSvc.ForwardGuestAgent(ctx, &emptypb.Empty{})
252252
if err != nil {
253-
d.logger.Errorf("Failed to check guest agent forwarding: %v", err)
253+
d.logger.WithError(err).Error("Failed to check guest agent forwarding")
254254
return false
255255
}
256256

@@ -261,7 +261,7 @@ func (d *DriverClient) GuestAgentConn(ctx context.Context) (net.Conn, string, er
261261
d.logger.Info("Getting guest agent connection")
262262
_, err := d.DriverSvc.GuestAgentConn(ctx, &emptypb.Empty{})
263263
if err != nil {
264-
d.logger.Errorf("Failed to get guest agent connection: %v", err)
264+
d.logger.WithError(err).Error("Failed to get guest agent connection")
265265
return nil, "", err
266266
}
267267

@@ -276,13 +276,13 @@ func (d *DriverClient) Info() driver.Info {
276276

277277
resp, err := d.DriverSvc.Info(ctx, &emptypb.Empty{})
278278
if err != nil {
279-
d.logger.Errorf("Failed to get driver info: %v", err)
279+
d.logger.WithError(err).Error("Failed to get driver info")
280280
return driver.Info{}
281281
}
282282

283283
var info driver.Info
284284
if err := json.Unmarshal(resp.InfoJson, &info); err != nil {
285-
d.logger.Errorf("Failed to unmarshal driver info: %v", err)
285+
d.logger.WithError(err).Error("Failed to unmarshal driver info")
286286
return driver.Info{}
287287
}
288288

@@ -295,7 +295,7 @@ func (d *DriverClient) Configure(inst *limatype.Instance) *driver.ConfiguredDriv
295295

296296
instJSON, err := inst.MarshalJSON()
297297
if err != nil {
298-
d.logger.Errorf("Failed to marshal instance config: %v", err)
298+
d.logger.WithError(err).Error("Failed to marshal instance config")
299299
return nil
300300
}
301301

@@ -306,7 +306,7 @@ func (d *DriverClient) Configure(inst *limatype.Instance) *driver.ConfiguredDriv
306306
InstanceConfigJson: instJSON,
307307
})
308308
if err != nil {
309-
d.logger.Errorf("Failed to set config: %v", err)
309+
d.logger.WithError(err).Error("Failed to set config")
310310
return nil
311311
}
312312

@@ -325,7 +325,7 @@ func (d *DriverClient) SSHAddress(ctx context.Context) (string, error) {
325325

326326
resp, err := d.DriverSvc.SSHAddress(ctx, &emptypb.Empty{})
327327
if err != nil {
328-
d.logger.Errorf("Failed to get SSH address: %v", err)
328+
d.logger.WithError(err).Error("Failed to get SSH address")
329329
return "", err
330330
}
331331

@@ -337,7 +337,7 @@ func (d *DriverClient) BootScripts() (map[string][]byte, error) {
337337
d.logger.Debug("Getting boot scripts for the driver instance")
338338
resp, err := d.DriverSvc.BootScripts(context.Background(), &emptypb.Empty{})
339339
if err != nil {
340-
d.logger.Errorf("Failed to get boot scripts: %v", err)
340+
d.logger.WithError(err).Error("Failed to get boot scripts")
341341
return nil, err
342342
}
343343

@@ -350,7 +350,7 @@ func (d *DriverClient) AdditionalSetupForSSH(ctx context.Context) error {
350350

351351
_, err := d.DriverSvc.AdditionalSetupForSSH(ctx, &emptypb.Empty{})
352352
if err != nil {
353-
d.logger.Errorf("Failed to perform additional setup for SSH: %v", err)
353+
d.logger.WithError(err).Error("Failed to perform additional setup for SSH")
354354
return err
355355
}
356356

0 commit comments

Comments
 (0)