@@ -5,6 +5,7 @@ package podman
55
66import (
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(
149149func 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) {
192192func 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