Skip to content

Commit 197c87d

Browse files
committed
Remove dependency on github.com/hashicorp/go-multierror
Signed-off-by: Akihiro Suda <[email protected]>
1 parent e5e2d2e commit 197c87d

File tree

6 files changed

+20
-30
lines changed

6 files changed

+20
-30
lines changed

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ require (
2222
github.com/goccy/go-yaml v1.11.0
2323
github.com/google/go-cmp v0.5.9
2424
github.com/gorilla/mux v1.8.0
25-
github.com/hashicorp/go-multierror v1.1.1
2625
github.com/lima-vm/go-qcow2reader v0.1.1
2726
github.com/lima-vm/sshocker v0.3.3
2827
github.com/lithammer/dedent v1.1.0
@@ -75,7 +74,6 @@ require (
7574
github.com/google/gnostic v0.5.7-v3refs // indirect
7675
github.com/google/gofuzz v1.2.0 // indirect
7776
github.com/google/gopacket v1.1.19 // indirect
78-
github.com/hashicorp/errwrap v1.1.0 // indirect
7977
github.com/imdario/mergo v0.3.13 // indirect
8078
github.com/inconshreveable/mousetrap v1.1.0 // indirect
8179
github.com/insomniacslk/dhcp v0.0.0-20220504074936-1ca156eafb9f // indirect

go.sum

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
137137
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
138138
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
139139
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
140-
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
141-
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
142-
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
143-
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
144-
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
145140
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
146141
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
147142
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=

pkg/hostagent/hostagent.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/lima-vm/lima/pkg/driverutil"
2121
"github.com/lima-vm/lima/pkg/networks"
2222

23-
"github.com/hashicorp/go-multierror"
2423
"github.com/lima-vm/lima/pkg/cidata"
2524
guestagentapi "github.com/lima-vm/lima/pkg/guestagent/api"
2625
guestagentclient "github.com/lima-vm/lima/pkg/guestagent/api/client"
@@ -402,7 +401,7 @@ func (a *HostAgent) startHostAgentRoutines(ctx context.Context) error {
402401
})
403402
var mErr error
404403
if err := a.waitForRequirements("essential", a.essentialRequirements()); err != nil {
405-
mErr = multierror.Append(mErr, err)
404+
mErr = errors.Join(mErr, err)
406405
}
407406
if *a.y.SSH.ForwardAgent {
408407
faScript := `#!/bin/bash
@@ -414,19 +413,19 @@ sudo chown -R "${USER}" /run/host-services`
414413
stdout, stderr, err := ssh.ExecuteScript("127.0.0.1", a.sshLocalPort, a.sshConfig, faScript, faDesc)
415414
logrus.Debugf("stdout=%q, stderr=%q, err=%v", stdout, stderr, err)
416415
if err != nil {
417-
mErr = multierror.Append(mErr, fmt.Errorf("stdout=%q, stderr=%q: %w", stdout, stderr, err))
416+
mErr = errors.Join(mErr, fmt.Errorf("stdout=%q, stderr=%q: %w", stdout, stderr, err))
418417
}
419418
}
420419
if *a.y.MountType == limayaml.REVSSHFS {
421420
mounts, err := a.setupMounts()
422421
if err != nil {
423-
mErr = multierror.Append(mErr, err)
422+
mErr = errors.Join(mErr, err)
424423
}
425424
a.onClose = append(a.onClose, func() error {
426425
var unmountMErr error
427426
for _, m := range mounts {
428427
if unmountErr := m.close(); unmountErr != nil {
429-
unmountMErr = multierror.Append(unmountMErr, unmountErr)
428+
unmountMErr = errors.Join(unmountMErr, unmountErr)
430429
}
431430
}
432431
return unmountMErr
@@ -438,28 +437,28 @@ sudo chown -R "${USER}" /run/host-services`
438437
for _, d := range a.y.AdditionalDisks {
439438
disk, inspectErr := store.InspectDisk(d.Name)
440439
if inspectErr != nil {
441-
unlockMErr = multierror.Append(unlockMErr, inspectErr)
440+
unlockMErr = errors.Join(unlockMErr, inspectErr)
442441
continue
443442
}
444443
logrus.Infof("Unmounting disk %q", disk.Name)
445444
if unlockErr := disk.Unlock(); unlockErr != nil {
446-
unlockMErr = multierror.Append(unlockMErr, unlockErr)
445+
unlockMErr = errors.Join(unlockMErr, unlockErr)
447446
}
448447
}
449448
return unlockMErr
450449
})
451450
}
452451
go a.watchGuestAgentEvents(ctx)
453452
if err := a.waitForRequirements("optional", a.optionalRequirements()); err != nil {
454-
mErr = multierror.Append(mErr, err)
453+
mErr = errors.Join(mErr, err)
455454
}
456455
if err := a.waitForRequirements("final", a.finalRequirements()); err != nil {
457-
mErr = multierror.Append(mErr, err)
456+
mErr = errors.Join(mErr, err)
458457
}
459458
// Copy all config files _after_ the requirements are done
460459
for _, rule := range a.y.CopyToHost {
461460
if err := copyToHost(ctx, a.sshConfig, a.sshLocalPort, rule.HostFile, rule.GuestFile); err != nil {
462-
mErr = multierror.Append(mErr, err)
461+
mErr = errors.Join(mErr, err)
463462
}
464463
}
465464
return mErr
@@ -471,7 +470,7 @@ func (a *HostAgent) close() error {
471470
for i := len(a.onClose) - 1; i >= 0; i-- {
472471
f := a.onClose[i]
473472
if err := f(); err != nil {
474-
mErr = multierror.Append(mErr, err)
473+
mErr = errors.Join(mErr, err)
475474
}
476475
}
477476
return mErr
@@ -500,12 +499,12 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
500499
local := hostAddress(rule, guestagentapi.IPPort{})
501500
// using ctx.Background() because ctx has already been cancelled
502501
if err := forwardSSH(context.Background(), a.sshConfig, a.sshLocalPort, local, rule.GuestSocket, verbCancel, rule.Reverse); err != nil {
503-
mErr = multierror.Append(mErr, err)
502+
mErr = errors.Join(mErr, err)
504503
}
505504
}
506505
}
507506
if err := forwardSSH(context.Background(), a.sshConfig, a.sshLocalPort, localUnix, remoteUnix, verbCancel, false); err != nil {
508-
mErr = multierror.Append(mErr, err)
507+
mErr = errors.Join(mErr, err)
509508
}
510509
return mErr
511510
})

pkg/hostagent/mount.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package hostagent
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
67

7-
"github.com/hashicorp/go-multierror"
8-
98
"github.com/lima-vm/lima/pkg/limayaml"
109
"github.com/lima-vm/lima/pkg/localpathutil"
1110
"github.com/lima-vm/sshocker/pkg/reversesshfs"
@@ -24,7 +23,7 @@ func (a *HostAgent) setupMounts() ([]*mount, error) {
2423
for _, f := range a.y.Mounts {
2524
m, err := a.setupMount(f)
2625
if err != nil {
27-
mErr = multierror.Append(mErr, err)
26+
mErr = errors.Join(mErr, err)
2827
continue
2928
}
3029
res = append(res, m)

pkg/hostagent/requirements.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package hostagent
22

33
import (
4+
"errors"
45
"fmt"
56
"time"
67

7-
"github.com/hashicorp/go-multierror"
88
"github.com/lima-vm/lima/pkg/limayaml"
99
"github.com/lima-vm/sshocker/pkg/ssh"
1010
"github.com/sirupsen/logrus"
@@ -28,10 +28,10 @@ func (a *HostAgent) waitForRequirements(label string, requirements []requirement
2828
}
2929
if req.fatal {
3030
logrus.Infof("No further %s requirements will be checked", label)
31-
return multierror.Append(mErr, fmt.Errorf("failed to satisfy the %s requirement %d of %d %q: %s; skipping further checks: %w", label, i+1, len(requirements), req.description, req.debugHint, err))
31+
return errors.Join(mErr, fmt.Errorf("failed to satisfy the %s requirement %d of %d %q: %s; skipping further checks: %w", label, i+1, len(requirements), req.description, req.debugHint, err))
3232
}
3333
if j == retries-1 {
34-
mErr = multierror.Append(mErr, fmt.Errorf("failed to satisfy the %s requirement %d of %d %q: %s: %w", label, i+1, len(requirements), req.description, req.debugHint, err))
34+
mErr = errors.Join(mErr, fmt.Errorf("failed to satisfy the %s requirement %d of %d %q: %s: %w", label, i+1, len(requirements), req.description, req.debugHint, err))
3535
break retryLoop
3636
}
3737
time.Sleep(10 * time.Second)

pkg/qemu/qemu_driver.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020

2121
"github.com/digitalocean/go-qemu/qmp"
2222
"github.com/digitalocean/go-qemu/qmp/raw"
23-
"github.com/hashicorp/go-multierror"
2423
"github.com/lima-vm/lima/pkg/driver"
2524
"github.com/lima-vm/lima/pkg/limayaml"
2625
"github.com/lima-vm/lima/pkg/networks/usernet"
@@ -286,7 +285,7 @@ func (l *LimaQemuDriver) killVhosts() error {
286285
var mErr error
287286
for i, vhost := range l.vhostCmds {
288287
if err := vhost.Process.Kill(); err != nil && !errors.Is(err, os.ErrProcessDone) {
289-
mErr = multierror.Append(mErr, fmt.Errorf("Failed to kill virtiofsd instance #%d: %w", i, err))
288+
mErr = errors.Join(mErr, fmt.Errorf("Failed to kill virtiofsd instance #%d: %w", i, err))
290289
}
291290
}
292291

@@ -324,7 +323,7 @@ func (l *LimaQemuDriver) shutdownQEMU(ctx context.Context, timeout time.Duration
324323
case qWaitErr := <-qWaitCh:
325324
logrus.WithError(qWaitErr).Info("QEMU has exited")
326325
l.removeVNCFiles()
327-
return multierror.Append(qWaitErr, l.killVhosts()).ErrorOrNil()
326+
return errors.Join(qWaitErr, l.killVhosts())
328327
case <-deadline:
329328
}
330329
logrus.Warnf("QEMU did not exit in %v, forcibly killing QEMU", timeout)
@@ -345,7 +344,7 @@ func (l *LimaQemuDriver) killQEMU(_ context.Context, _ time.Duration, qCmd *exec
345344
qemuPIDPath := filepath.Join(l.Instance.Dir, filenames.PIDFile(*l.Yaml.VMType))
346345
_ = os.RemoveAll(qemuPIDPath)
347346
l.removeVNCFiles()
348-
return multierror.Append(qWaitErr, l.killVhosts()).ErrorOrNil()
347+
return errors.Join(qWaitErr, l.killVhosts())
349348
}
350349

351350
func newUsernetClient(nwName string) *usernet.Client {

0 commit comments

Comments
 (0)