Skip to content

Commit 8092199

Browse files
authored
Merge pull request #166 from AkihiroSuda/remove-pkg-errors
remove direct dependency on github.com/pkg/errors
2 parents b499494 + 34bb35b commit 8092199

File tree

27 files changed

+156
-160
lines changed

27 files changed

+156
-160
lines changed

cmd/lima-guestagent/daemon_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"path/filepath"
99
"time"
1010

11+
"github.com/gorilla/mux"
1112
"github.com/lima-vm/lima/pkg/guestagent"
1213
"github.com/lima-vm/lima/pkg/guestagent/api/server"
13-
"github.com/gorilla/mux"
1414
"github.com/sirupsen/logrus"
1515
"github.com/urfave/cli/v2"
1616
)

cmd/limactl/copy.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
67
"os/exec"
@@ -9,7 +10,6 @@ import (
910

1011
"github.com/lima-vm/lima/pkg/sshutil"
1112
"github.com/lima-vm/lima/pkg/store"
12-
"github.com/pkg/errors"
1313
"github.com/sirupsen/logrus"
1414
"github.com/urfave/cli/v2"
1515
)
@@ -25,7 +25,7 @@ var copyCommand = &cli.Command{
2525

2626
func copyAction(clicontext *cli.Context) error {
2727
if clicontext.NArg() < 2 {
28-
return errors.Errorf("requires at least 2 arguments: SOURCE DEST")
28+
return fmt.Errorf("requires at least 2 arguments: SOURCE DEST")
2929
}
3030
arg0, err := exec.LookPath("scp")
3131
if err != nil {
@@ -52,16 +52,16 @@ func copyAction(clicontext *cli.Context) error {
5252
inst, err := store.Inspect(instName)
5353
if err != nil {
5454
if errors.Is(err, os.ErrNotExist) {
55-
return errors.Errorf("instance %q does not exist, run `limactl start %s` to create a new instance", instName, instName)
55+
return fmt.Errorf("instance %q does not exist, run `limactl start %s` to create a new instance", instName, instName)
5656
}
5757
return err
5858
}
5959
if inst.Status == store.StatusStopped {
60-
return errors.Errorf("instance %q is stopped, run `limactl start %s` to start the instance", instName, instName)
60+
return fmt.Errorf("instance %q is stopped, run `limactl start %s` to start the instance", instName, instName)
6161
}
6262
args = append(args, fmt.Sprintf("scp://%[email protected]:%d/%s", u.Username, inst.SSHLocalPort, path[1]))
6363
default:
64-
return errors.Errorf("Path %q contains multiple colons", arg)
64+
return fmt.Errorf("Path %q contains multiple colons", arg)
6565
}
6666
}
6767
cmd := exec.Command(arg0, args...)

cmd/limactl/delete.go

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

33
import (
4+
"errors"
5+
"fmt"
46
"os"
57

68
"github.com/lima-vm/lima/pkg/store"
7-
"github.com/pkg/errors"
89
"github.com/sirupsen/logrus"
910
"github.com/urfave/cli/v2"
1011
)
@@ -27,7 +28,7 @@ var deleteCommand = &cli.Command{
2728

2829
func deleteAction(clicontext *cli.Context) error {
2930
if clicontext.NArg() == 0 {
30-
return errors.Errorf("requires at least 1 argument")
31+
return fmt.Errorf("requires at least 1 argument")
3132
}
3233
force := clicontext.Bool("force")
3334
for _, instName := range clicontext.Args().Slice() {
@@ -40,7 +41,7 @@ func deleteAction(clicontext *cli.Context) error {
4041
return err
4142
}
4243
if err := deleteInstance(inst, force); err != nil {
43-
return errors.Wrapf(err, "failed to delete instance %q", instName)
44+
return fmt.Errorf("failed to delete instance %q: %w", instName, err)
4445
}
4546
logrus.Infof("Deleted %q (%q)", instName, inst.Dir)
4647
}
@@ -49,13 +50,13 @@ func deleteAction(clicontext *cli.Context) error {
4950

5051
func deleteInstance(inst *store.Instance, force bool) error {
5152
if !force && inst.Status != store.StatusStopped {
52-
return errors.Errorf("expected status %q, got %q", store.StatusStopped, inst.Status)
53+
return fmt.Errorf("expected status %q, got %q", store.StatusStopped, inst.Status)
5354
}
5455

5556
stopInstanceForcibly(inst)
5657

5758
if err := os.RemoveAll(inst.Dir); err != nil {
58-
return errors.Wrapf(err, "failed to remove %q", inst.Dir)
59+
return fmt.Errorf("failed to remove %q: %w", inst.Dir, err)
5960
}
6061
return nil
6162
}

cmd/limactl/hostagent.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package main
22

33
import (
4+
"errors"
5+
"fmt"
46
"io"
57
"os"
68
"os/signal"
79
"strconv"
810

911
"github.com/lima-vm/lima/pkg/hostagent"
10-
"github.com/pkg/errors"
1112
"github.com/urfave/cli/v2"
1213
)
1314

@@ -29,7 +30,7 @@ var hostagentCommand = &cli.Command{
2930
func hostagentAction(clicontext *cli.Context) error {
3031
if pidfile := clicontext.String("pidfile"); pidfile != "" {
3132
if _, err := os.Stat(pidfile); !errors.Is(err, os.ErrNotExist) {
32-
return errors.Errorf("pidfile %q already exists", pidfile)
33+
return fmt.Errorf("pidfile %q already exists", pidfile)
3334
}
3435
if err := os.WriteFile(pidfile, []byte(strconv.Itoa(os.Getpid())+"\n"), 0644); err != nil {
3536
return err
@@ -38,7 +39,7 @@ func hostagentAction(clicontext *cli.Context) error {
3839
}
3940

4041
if clicontext.NArg() != 1 {
41-
return errors.Errorf("requires exactly 1 argument")
42+
return fmt.Errorf("requires exactly 1 argument")
4243
}
4344

4445
instName := clicontext.Args().First()

cmd/limactl/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package main
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"text/tabwriter"
78

89
"github.com/lima-vm/lima/pkg/store"
9-
"github.com/pkg/errors"
1010
"github.com/sirupsen/logrus"
1111
"github.com/urfave/cli/v2"
1212
)

cmd/limactl/shell.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
67
"os/exec"
@@ -11,7 +12,6 @@ import (
1112
"github.com/lima-vm/lima/pkg/sshutil"
1213
"github.com/lima-vm/lima/pkg/store"
1314
"github.com/mattn/go-isatty"
14-
"github.com/pkg/errors"
1515
"github.com/sirupsen/logrus"
1616
"github.com/urfave/cli/v2"
1717
)
@@ -34,7 +34,7 @@ var shellCommand = &cli.Command{
3434

3535
func shellAction(clicontext *cli.Context) error {
3636
if clicontext.NArg() == 0 {
37-
return errors.Errorf("requires at least 1 argument")
37+
return fmt.Errorf("requires at least 1 argument")
3838
}
3939
instName := clicontext.Args().First()
4040

@@ -50,12 +50,12 @@ func shellAction(clicontext *cli.Context) error {
5050
inst, err := store.Inspect(instName)
5151
if err != nil {
5252
if errors.Is(err, os.ErrNotExist) {
53-
return errors.Errorf("instance %q does not exist, run `limactl start %s` to create a new instance", instName, instName)
53+
return fmt.Errorf("instance %q does not exist, run `limactl start %s` to create a new instance", instName, instName)
5454
}
5555
return err
5656
}
5757
if inst.Status == store.StatusStopped {
58-
return errors.Errorf("instance %q is stopped, run `limactl start %s` to start the instance", instName, instName)
58+
return fmt.Errorf("instance %q is stopped, run `limactl start %s` to start the instance", instName, instName)
5959
}
6060
y, err := inst.LoadYAML()
6161
if err != nil {

cmd/limactl/start.go

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

33
import (
4+
"errors"
45
"fmt"
56
"io/ioutil"
67
"os"
@@ -17,7 +18,6 @@ import (
1718
"github.com/lima-vm/lima/pkg/store/filenames"
1819
"github.com/mattn/go-isatty"
1920
"github.com/norouter/norouter/cmd/norouter/editorcmd"
20-
"github.com/pkg/errors"
2121
"github.com/sirupsen/logrus"
2222
"github.com/urfave/cli/v2"
2323
)
@@ -39,7 +39,7 @@ var startCommand = &cli.Command{
3939

4040
func loadOrCreateInstance(clicontext *cli.Context) (*store.Instance, error) {
4141
if clicontext.NArg() > 1 {
42-
return nil, errors.Errorf("too many arguments")
42+
return nil, fmt.Errorf("too many arguments")
4343
}
4444

4545
arg := clicontext.Args().First()
@@ -67,7 +67,7 @@ func loadOrCreateInstance(clicontext *cli.Context) (*store.Instance, error) {
6767
instName = arg
6868
logrus.Debugf("interpreting argument %q as an instance name %q", arg, instName)
6969
if err := identifiers.Validate(instName); err != nil {
70-
return nil, errors.Wrapf(err, "argument must be either an instance name or a YAML file path, got %q", instName)
70+
return nil, fmt.Errorf("argument must be either an instance name or a YAML file path, got %q: %w", instName, err)
7171
}
7272
if inst, err := store.Inspect(instName); err == nil {
7373
logrus.Infof("Using the existing instance %q", instName)
@@ -87,11 +87,11 @@ func loadOrCreateInstance(clicontext *cli.Context) (*store.Instance, error) {
8787
// the full path of the socket name must be less than UNIX_PATH_MAX chars.
8888
maxSockName := filepath.Join(instDir, filenames.LongestSock)
8989
if len(maxSockName) >= osutil.UnixPathMax {
90-
return nil, errors.Errorf("instance name %q too long: %q must be less than UNIX_PATH_MAX=%d characers, but is %d",
90+
return nil, fmt.Errorf("instance name %q too long: %q must be less than UNIX_PATH_MAX=%d characers, but is %d",
9191
instName, maxSockName, osutil.UnixPathMax, len(maxSockName))
9292
}
9393
if _, err := os.Stat(instDir); !errors.Is(err, os.ErrNotExist) {
94-
return nil, errors.Errorf("instance %q already exists (%q)", instName, instDir)
94+
return nil, fmt.Errorf("instance %q already exists (%q)", instName, instDir)
9595
}
9696

9797
if clicontext.Bool("tty") {
@@ -126,9 +126,9 @@ func loadOrCreateInstance(clicontext *cli.Context) (*store.Instance, error) {
126126
}
127127
rejectedYAML := "lima.REJECTED.yaml"
128128
if writeErr := os.WriteFile(rejectedYAML, yBytes, 0644); writeErr != nil {
129-
return nil, errors.Wrapf(err, "the YAML is invalid, attempted to save the buffer as %q but failed: %v", rejectedYAML, writeErr)
129+
return nil, fmt.Errorf("the YAML is invalid, attempted to save the buffer as %q but failed: %v: %w", rejectedYAML, writeErr, err)
130130
}
131-
return nil, errors.Wrapf(err, "the YAML is invalid, saved the buffer as %q", rejectedYAML)
131+
return nil, fmt.Errorf("the YAML is invalid, saved the buffer as %q: %w", rejectedYAML, err)
132132
}
133133
if err := os.MkdirAll(instDir, 0700); err != nil {
134134
return nil, err
@@ -161,7 +161,7 @@ func askWhetherToOpenEditor(name string) (bool, error) {
161161
os.Exit(0)
162162
return false, errors.New("should not reach here")
163163
default:
164-
return false, errors.Errorf("unexpected answer %q", ans)
164+
return false, fmt.Errorf("unexpected answer %q", ans)
165165
}
166166
}
167167

@@ -198,7 +198,7 @@ func openEditor(clicontext *cli.Context, name string, initialContent []byte) ([]
198198
editorCmd.Stderr = os.Stderr
199199
logrus.Debugf("opening editor %q for a file %q", editor, tmpYAMLPath)
200200
if err := editorCmd.Run(); err != nil {
201-
return nil, errors.Wrapf(err, "could not execute editor %q for a file %q", editor, tmpYAMLPath)
201+
return nil, fmt.Errorf("could not execute editor %q for a file %q: %w", editor, tmpYAMLPath, err)
202202
}
203203
b, err := os.ReadFile(tmpYAMLPath)
204204
if err != nil {
@@ -245,7 +245,7 @@ func instNameFromYAMLPath(yamlPath string) (string, error) {
245245
s = strings.TrimSuffix(strings.TrimSuffix(s, ".yml"), ".yaml")
246246
s = strings.ReplaceAll(s, ".", "-")
247247
if err := identifiers.Validate(s); err != nil {
248-
return "", errors.Wrapf(err, "filename %q is invalid", yamlPath)
248+
return "", fmt.Errorf("filename %q is invalid: %w", yamlPath, err)
249249
}
250250
return s, nil
251251
}

cmd/limactl/stop.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"context"
5+
"errors"
6+
"fmt"
57
"os"
68
"path/filepath"
79
"strings"
@@ -11,7 +13,6 @@ import (
1113
hostagentapi "github.com/lima-vm/lima/pkg/hostagent/api"
1214
"github.com/lima-vm/lima/pkg/store"
1315
"github.com/lima-vm/lima/pkg/store/filenames"
14-
"github.com/pkg/errors"
1516
"github.com/sirupsen/logrus"
1617
"github.com/urfave/cli/v2"
1718
)
@@ -33,7 +34,7 @@ var stopCommand = &cli.Command{
3334

3435
func stopAction(clicontext *cli.Context) error {
3536
if clicontext.NArg() > 1 {
36-
return errors.Errorf("too many arguments")
37+
return fmt.Errorf("too many arguments")
3738
}
3839

3940
instName := clicontext.Args().First()
@@ -56,7 +57,7 @@ func stopAction(clicontext *cli.Context) error {
5657

5758
func stopInstanceGracefully(inst *store.Instance) error {
5859
if inst.Status != store.StatusRunning {
59-
return errors.Errorf("expected status %q, got %q", store.StatusRunning, inst.Status)
60+
return fmt.Errorf("expected status %q, got %q", store.StatusRunning, inst.Status)
6061
}
6162

6263
begin := time.Now() // used for logrus propagation

cmd/limactl/validate.go

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

33
import (
4+
"fmt"
5+
46
"github.com/lima-vm/lima/pkg/store"
5-
"github.com/pkg/errors"
7+
68
"github.com/sirupsen/logrus"
79
"github.com/urfave/cli/v2"
810
)
@@ -16,13 +18,13 @@ var validateCommand = &cli.Command{
1618

1719
func validateAction(clicontext *cli.Context) error {
1820
if clicontext.NArg() == 0 {
19-
return errors.Errorf("requires at least 1 argument")
21+
return fmt.Errorf("requires at least 1 argument")
2022
}
2123

2224
for _, f := range clicontext.Args().Slice() {
2325
_, err := store.LoadYAMLByFilePath(f)
2426
if err != nil {
25-
return errors.Wrapf(err, "failed to load YAML file %q", f)
27+
return fmt.Errorf("failed to load YAML file %q: %w", f, err)
2628
}
2729
if _, err := instNameFromYAMLPath(f); err != nil {
2830
return err

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ require (
1919
github.com/norouter/norouter v0.6.4
2020
github.com/nxadm/tail v1.4.8
2121
github.com/opencontainers/go-digest v1.0.0
22-
github.com/pkg/errors v0.9.1
2322
github.com/sirupsen/logrus v1.8.1
2423
github.com/urfave/cli/v2 v2.3.0
2524
github.com/yalue/native_endian v1.0.1

0 commit comments

Comments
 (0)