Skip to content

Commit ea7f84e

Browse files
authored
Replace github.com/pkg/errors by stdlib packages (#2962)
None of the extra features of the 3rd party `github.com/pkg/errors` package are needed, so use the standard library `errors.New` and `fmt.Errorf` available since Go 1.13, like already done in lots of places elsewhere in the code base.
1 parent ecee770 commit ea7f84e

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ require (
3535
github.com/minio/minio-go/v7 v7.0.95
3636
github.com/mitchellh/go-homedir v1.1.0
3737
github.com/opencontainers/runtime-spec v1.2.0
38-
github.com/pkg/errors v0.9.1
3938
github.com/pmorjan/kmod v1.1.1
4039
github.com/scrapli/scrapligo v1.3.3
4140
github.com/scrapli/scrapligocfg v1.0.0
@@ -130,6 +129,7 @@ require (
130129
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
131130
github.com/philhofer/fwd v1.2.0 // indirect
132131
github.com/pjbgf/sha1cd v0.3.2 // indirect
132+
github.com/pkg/errors v0.9.1 // indirect
133133
github.com/pkg/sftp v1.13.7 // indirect
134134
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
135135
github.com/rs/xid v1.6.0 // indirect

nodes/srl/srl.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"time"
2121

2222
"github.com/charmbracelet/log"
23-
"github.com/pkg/errors"
2423
"golang.org/x/crypto/ssh"
2524

2625
clabcert "github.com/srl-labs/containerlab/cert"
@@ -606,7 +605,7 @@ func generateSRLTopologyFile(cfg *clabtypes.NodeConfig) error {
606605

607606
tpl, err := template.ParseFS(topologies, "topology/"+srlTypes[cfg.NodeType])
608607
if err != nil {
609-
return errors.Wrap(err, "failed to get srl topology file")
608+
return fmt.Errorf("failed to get srl topology file: %w", err)
610609
}
611610

612611
mac := genMac(cfg)

runtime/podman/portmaps.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package podman
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"net"
1011
"strconv"
@@ -14,7 +15,6 @@ import (
1415

1516
"github.com/charmbracelet/log"
1617
"github.com/docker/go-connections/nat"
17-
"github.com/pkg/errors"
1818
)
1919

2020
// Reusing parts of the code from podman specgenutil/util.go
@@ -95,18 +95,18 @@ func parseSplitPort(
9595
) (netTypes.PortMapping, error) {
9696
newPort := netTypes.PortMapping{}
9797
if ctrPort == "" {
98-
return newPort, errors.Errorf("must provide a non-empty container port to publish")
98+
return newPort, errors.New("must provide a non-empty container port to publish")
9999
}
100100
ctrStart, ctrLen, err := parseAndValidateRange(ctrPort)
101101
if err != nil {
102-
return newPort, errors.Wrapf(err, "error parsing container port")
102+
return newPort, fmt.Errorf("error parsing container port: %w", err)
103103
}
104104
newPort.ContainerPort = ctrStart
105105
newPort.Range = ctrLen
106106

107107
if protocol != nil {
108108
if *protocol == "" {
109-
return newPort, errors.Errorf("must provide a non-empty protocol to publish")
109+
return newPort, errors.New("must provide a non-empty protocol to publish")
110110
}
111111
newPort.Protocol = *protocol
112112
}
@@ -116,7 +116,7 @@ func parseSplitPort(
116116
if *hostIP != "" && *hostIP != "0.0.0.0" {
117117
testIP := net.ParseIP(*hostIP)
118118
if testIP == nil {
119-
return newPort, errors.Errorf("cannot parse %q as an IP address", *hostIP)
119+
return newPort, fmt.Errorf("cannot parse %q as an IP address", *hostIP)
120120
}
121121
newPort.HostIP = testIP.String()
122122
}
@@ -129,10 +129,10 @@ func parseSplitPort(
129129
} else {
130130
hostStart, hostLen, err := parseAndValidateRange(*hostPort)
131131
if err != nil {
132-
return newPort, errors.Wrapf(err, "error parsing host port")
132+
return newPort, fmt.Errorf("error parsing host port: %w", err)
133133
}
134134
if hostLen != ctrLen {
135-
return newPort, errors.Errorf("host and container port ranges have different lengths: %d vs %d", hostLen, ctrLen)
135+
return newPort, fmt.Errorf("host and container port ranges have different lengths: %d vs %d", hostLen, ctrLen)
136136
}
137137
newPort.HostPort = hostStart
138138
}
@@ -149,13 +149,13 @@ func parseSplitPort(
149149
func parseAndValidateRange(portRange string) (uint16, uint16, error) {
150150
splitRange := strings.Split(portRange, "-")
151151
if len(splitRange) > 2 {
152-
return 0, 0, errors.Errorf(
152+
return 0, 0, errors.New(
153153
"invalid port format - port ranges are formatted as startPort-stopPort",
154154
)
155155
}
156156

157157
if splitRange[0] == "" {
158-
return 0, 0, errors.Errorf("port numbers cannot be negative")
158+
return 0, 0, errors.New("port numbers cannot be negative")
159159
}
160160

161161
startPort, err := parseAndValidatePort(splitRange[0])
@@ -166,14 +166,14 @@ func parseAndValidateRange(portRange string) (uint16, uint16, error) {
166166
var rangeLen uint16 = 1
167167
if len(splitRange) == 2 {
168168
if splitRange[1] == "" {
169-
return 0, 0, errors.Errorf("must provide ending number for port range")
169+
return 0, 0, errors.New("must provide ending number for port range")
170170
}
171171
endPort, err := parseAndValidatePort(splitRange[1])
172172
if err != nil {
173173
return 0, 0, err
174174
}
175175
if endPort <= startPort {
176-
return 0, 0, errors.Errorf(
176+
return 0, 0, fmt.Errorf(
177177
"the end port of a range must be higher than the start port - %d is not higher than %d",
178178
endPort,
179179
startPort,
@@ -192,10 +192,10 @@ func parseAndValidateRange(portRange string) (uint16, uint16, error) {
192192
func parseAndValidatePort(port string) (uint16, error) {
193193
num, err := strconv.Atoi(port)
194194
if err != nil {
195-
return 0, errors.Wrapf(err, "invalid port number")
195+
return 0, fmt.Errorf("invalid port number: %w", err)
196196
}
197197
if num < 1 || num > 65535 {
198-
return 0, errors.Errorf("port numbers must be between 1 and 65535 (inclusive), got %d", num)
198+
return 0, fmt.Errorf("port numbers must be between 1 and 65535 (inclusive), got %d", num)
199199
}
200200
return uint16(num), nil
201201
}

0 commit comments

Comments
 (0)