1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

chore: remove github.com/pkg/errors (#873)

The functionality provided by this package is also provided by the
standard library.

`fmt.Errorf` for dynamically generated errors.
`errors.new` for static errors.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/873): <!--number 873 --><!--line 0 --><!--description Y2hvcmU6IHJlbW92ZSBgZ2l0aHViLmNvbS9wa2cvZXJyb3JzYA==-->chore: remove `github.com/pkg/errors`<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/873
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2025-08-28 09:33:52 +00:00 committed by earl-warren
parent 0e780482eb
commit bbb2cdd9f7
No known key found for this signature in database
GPG key ID: F128CBE6AB3A7201
4 changed files with 36 additions and 36 deletions

View file

@ -13,6 +13,7 @@ package container
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"os" "os"
"path" "path"
@ -32,7 +33,6 @@ import (
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/errdefs" "github.com/docker/docker/errdefs"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
"github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
@ -331,7 +331,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
// Validate the input mac address // Validate the input mac address
if copts.macAddress != "" { if copts.macAddress != "" {
if _, err := opts.ValidateMACAddress(copts.macAddress); err != nil { if _, err := opts.ValidateMACAddress(copts.macAddress); err != nil {
return nil, errors.Errorf("%s is not a valid mac address", copts.macAddress) return nil, fmt.Errorf("%s is not a valid mac address", copts.macAddress)
} }
} }
if copts.stdin { if copts.stdin {
@ -347,7 +347,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
swappiness := copts.swappiness swappiness := copts.swappiness
if swappiness != -1 && (swappiness < 0 || swappiness > 100) { if swappiness != -1 && (swappiness < 0 || swappiness > 100) {
return nil, errors.Errorf("invalid value: %d. Valid memory swappiness range is 0-100", swappiness) return nil, fmt.Errorf("invalid value: %d. Valid memory swappiness range is 0-100", swappiness)
} }
mounts := copts.mounts.Value() mounts := copts.mounts.Value()
@ -430,7 +430,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
// Merge in exposed ports to the map of published ports // Merge in exposed ports to the map of published ports
for _, e := range copts.expose.GetSlice() { for _, e := range copts.expose.GetSlice() {
if strings.Contains(e, ":") { if strings.Contains(e, ":") {
return nil, errors.Errorf("invalid port format for --expose: %s", e) return nil, fmt.Errorf("invalid port format for --expose: %s", e)
} }
// support two formats for expose, original format <portnum>/[<proto>] // support two formats for expose, original format <portnum>/[<proto>]
// or <startport-endport>/[<proto>] // or <startport-endport>/[<proto>]
@ -439,7 +439,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
// if expose a port, the start and end port are the same // if expose a port, the start and end port are the same
start, end, err := nat.ParsePortRange(port) start, end, err := nat.ParsePortRange(port)
if err != nil { if err != nil {
return nil, errors.Errorf("invalid range format for --expose: %s, error: %s", e, err) return nil, fmt.Errorf("invalid range format for --expose: %s, error: %s", e, err)
} }
for i := start; i <= end; i++ { for i := start; i <= end; i++ {
p, err := nat.NewPort(proto, strconv.FormatUint(i, 10)) p, err := nat.NewPort(proto, strconv.FormatUint(i, 10))
@ -488,22 +488,22 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
pidMode := container.PidMode(copts.pidMode) pidMode := container.PidMode(copts.pidMode)
if !pidMode.Valid() { if !pidMode.Valid() {
return nil, errors.Errorf("--pid: invalid PID mode") return nil, errors.New("--pid: invalid PID mode")
} }
utsMode := container.UTSMode(copts.utsMode) utsMode := container.UTSMode(copts.utsMode)
if !utsMode.Valid() { if !utsMode.Valid() {
return nil, errors.Errorf("--uts: invalid UTS mode") return nil, errors.New("--uts: invalid UTS mode")
} }
usernsMode := container.UsernsMode(copts.usernsMode) usernsMode := container.UsernsMode(copts.usernsMode)
if !usernsMode.Valid() { if !usernsMode.Valid() {
return nil, errors.Errorf("--userns: invalid USER mode") return nil, errors.New("--userns: invalid USER mode")
} }
cgroupnsMode := container.CgroupnsMode(copts.cgroupnsMode) cgroupnsMode := container.CgroupnsMode(copts.cgroupnsMode)
if !cgroupnsMode.Valid() { if !cgroupnsMode.Valid() {
return nil, errors.Errorf("--cgroupns: invalid CGROUP mode") return nil, errors.New("--cgroupns: invalid CGROUP mode")
} }
restartPolicy, err := opts.ParseRestartPolicy(copts.restartPolicy) restartPolicy, err := opts.ParseRestartPolicy(copts.restartPolicy)
@ -537,7 +537,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
copts.healthRetries != 0 copts.healthRetries != 0
if copts.noHealthcheck { if copts.noHealthcheck {
if haveHealthSettings { if haveHealthSettings {
return nil, errors.Errorf("--no-healthcheck conflicts with --health-* options") return nil, errors.New("--no-healthcheck conflicts with --health-* options")
} }
test := strslice.StrSlice{"NONE"} test := strslice.StrSlice{"NONE"}
healthConfig = &container.HealthConfig{Test: test} healthConfig = &container.HealthConfig{Test: test}
@ -548,16 +548,16 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
probe = strslice.StrSlice(args) probe = strslice.StrSlice(args)
} }
if copts.healthInterval < 0 { if copts.healthInterval < 0 {
return nil, errors.Errorf("--health-interval cannot be negative") return nil, errors.New("--health-interval cannot be negative")
} }
if copts.healthTimeout < 0 { if copts.healthTimeout < 0 {
return nil, errors.Errorf("--health-timeout cannot be negative") return nil, errors.New("--health-timeout cannot be negative")
} }
if copts.healthRetries < 0 { if copts.healthRetries < 0 {
return nil, errors.Errorf("--health-retries cannot be negative") return nil, errors.New("--health-retries cannot be negative")
} }
if copts.healthStartPeriod < 0 { if copts.healthStartPeriod < 0 {
return nil, fmt.Errorf("--health-start-period cannot be negative") return nil, errors.New("--health-start-period cannot be negative")
} }
healthConfig = &container.HealthConfig{ healthConfig = &container.HealthConfig{
@ -677,7 +677,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
} }
if copts.autoRemove && !hostConfig.RestartPolicy.IsNone() { if copts.autoRemove && !hostConfig.RestartPolicy.IsNone() {
return nil, errors.Errorf("Conflicting options: --restart and --rm") return nil, errors.New("Conflicting options: --restart and --rm")
} }
// only set this value if the user provided the flag, else it should default to nil // only set this value if the user provided the flag, else it should default to nil
@ -741,7 +741,7 @@ func parseNetworkOpts(copts *containerOptions) (map[string]*networktypes.Endpoin
return nil, err return nil, err
} }
if _, ok := endpoints[n.Target]; ok { if _, ok := endpoints[n.Target]; ok {
return nil, errdefs.InvalidParameter(errors.Errorf("network %q is specified multiple times", n.Target)) return nil, errdefs.InvalidParameter(fmt.Errorf("network %q is specified multiple times", n.Target))
} }
// For backward compatibility: if no custom options are provided for the network, // For backward compatibility: if no custom options are provided for the network,
@ -838,7 +838,7 @@ func convertToStandardNotation(ports []string) ([]string, error) {
for _, param := range strings.Split(publish, ",") { for _, param := range strings.Split(publish, ",") {
opt := strings.Split(param, "=") opt := strings.Split(param, "=")
if len(opt) < 2 { if len(opt) < 2 {
return optsList, errors.Errorf("invalid publish opts format (should be name=value but got '%s')", param) return optsList, fmt.Errorf("invalid publish opts format (should be name=value but got '%s')", param)
} }
params[opt[0]] = opt[1] params[opt[0]] = opt[1]
@ -854,7 +854,7 @@ func convertToStandardNotation(ports []string) ([]string, error) {
func parseLoggingOpts(loggingDriver string, loggingOpts []string) (map[string]string, error) { func parseLoggingOpts(loggingDriver string, loggingOpts []string) (map[string]string, error) {
loggingOptsMap := opts.ConvertKVStringsToMap(loggingOpts) loggingOptsMap := opts.ConvertKVStringsToMap(loggingOpts)
if loggingDriver == "none" && len(loggingOpts) > 0 { if loggingDriver == "none" && len(loggingOpts) > 0 {
return map[string]string{}, errors.Errorf("invalid logging opts for driver %s", loggingDriver) return map[string]string{}, fmt.Errorf("invalid logging opts for driver %s", loggingDriver)
} }
return loggingOptsMap, nil return loggingOptsMap, nil
} }
@ -867,17 +867,17 @@ func parseSecurityOpts(securityOpts []string) ([]string, error) {
if strings.Contains(opt, ":") { if strings.Contains(opt, ":") {
con = strings.SplitN(opt, ":", 2) con = strings.SplitN(opt, ":", 2)
} else { } else {
return securityOpts, errors.Errorf("Invalid --security-opt: %q", opt) return securityOpts, fmt.Errorf("Invalid --security-opt: %q", opt)
} }
} }
if con[0] == "seccomp" && con[1] != "unconfined" { if con[0] == "seccomp" && con[1] != "unconfined" {
f, err := os.ReadFile(con[1]) f, err := os.ReadFile(con[1])
if err != nil { if err != nil {
return securityOpts, errors.Errorf("opening seccomp profile (%s) failed: %v", con[1], err) return securityOpts, fmt.Errorf("opening seccomp profile (%s) failed: %v", con[1], err)
} }
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
if err := json.Compact(b, f); err != nil { if err := json.Compact(b, f); err != nil {
return securityOpts, errors.Errorf("compacting json for seccomp profile (%s) failed: %v", con[1], err) return securityOpts, fmt.Errorf("compacting json for seccomp profile (%s) failed: %v", con[1], err)
} }
securityOpts[key] = fmt.Sprintf("seccomp=%s", b.Bytes()) securityOpts[key] = fmt.Sprintf("seccomp=%s", b.Bytes())
} }
@ -913,7 +913,7 @@ func parseStorageOpts(storageOpts []string) (map[string]string, error) {
opt := strings.SplitN(option, "=", 2) opt := strings.SplitN(option, "=", 2)
m[opt[0]] = opt[1] m[opt[0]] = opt[1]
} else { } else {
return nil, errors.Errorf("invalid storage option") return nil, errors.New("invalid storage option")
} }
} }
return m, nil return m, nil
@ -927,7 +927,7 @@ func parseDevice(device, serverOS string) (container.DeviceMapping, error) {
case "windows": case "windows":
return parseWindowsDevice(device) return parseWindowsDevice(device)
} }
return container.DeviceMapping{}, errors.Errorf("unknown server OS: %s", serverOS) return container.DeviceMapping{}, fmt.Errorf("unknown server OS: %s", serverOS)
} }
// parseLinuxDevice parses a device mapping string to a container.DeviceMapping struct // parseLinuxDevice parses a device mapping string to a container.DeviceMapping struct
@ -950,7 +950,7 @@ func parseLinuxDevice(device string) (container.DeviceMapping, error) {
case 1: case 1:
src = arr[0] src = arr[0]
default: default:
return container.DeviceMapping{}, errors.Errorf("invalid device specification: %s", device) return container.DeviceMapping{}, fmt.Errorf("invalid device specification: %s", device)
} }
if dst == "" { if dst == "" {
@ -980,7 +980,7 @@ func validateDeviceCgroupRule(val string) (string, error) {
return val, nil return val, nil
} }
return val, errors.Errorf("invalid device cgroup format '%s'", val) return val, fmt.Errorf("invalid device cgroup format '%s'", val)
} }
// validDeviceMode checks if the mode for device is valid or not. // validDeviceMode checks if the mode for device is valid or not.
@ -1012,7 +1012,7 @@ func validateDevice(val, serverOS string) (string, error) {
// Windows does validation entirely server-side // Windows does validation entirely server-side
return val, nil return val, nil
} }
return "", errors.Errorf("unknown server OS: %s", serverOS) return "", fmt.Errorf("unknown server OS: %s", serverOS)
} }
// validateLinuxPath is the implementation of validateDevice knowing that the // validateLinuxPath is the implementation of validateDevice knowing that the
@ -1027,12 +1027,12 @@ func validateLinuxPath(val string, validator func(string) bool) (string, error)
var mode string var mode string
if strings.Count(val, ":") > 2 { if strings.Count(val, ":") > 2 {
return val, errors.Errorf("bad format for path: %s", val) return val, fmt.Errorf("bad format for path: %s", val)
} }
split := strings.SplitN(val, ":", 3) split := strings.SplitN(val, ":", 3)
if split[0] == "" { if split[0] == "" {
return val, errors.Errorf("bad format for path: %s", val) return val, fmt.Errorf("bad format for path: %s", val)
} }
switch len(split) { switch len(split) {
case 1: case 1:
@ -1051,13 +1051,13 @@ func validateLinuxPath(val string, validator func(string) bool) (string, error)
containerPath = split[1] containerPath = split[1]
mode = split[2] mode = split[2]
if isValid := validator(split[2]); !isValid { if isValid := validator(split[2]); !isValid {
return val, errors.Errorf("bad mode specified: %s", mode) return val, fmt.Errorf("bad mode specified: %s", mode)
} }
val = fmt.Sprintf("%s:%s:%s", split[0], containerPath, mode) val = fmt.Sprintf("%s:%s:%s", split[0], containerPath, mode)
} }
if !path.IsAbs(containerPath) { if !path.IsAbs(containerPath) {
return val, errors.Errorf("%s is not an absolute path", containerPath) return val, fmt.Errorf("%s is not an absolute path", containerPath)
} }
return val, nil return val, nil
} }
@ -1070,13 +1070,13 @@ func validateAttach(val string) (string, error) {
return s, nil return s, nil
} }
} }
return val, errors.Errorf("valid streams are STDIN, STDOUT and STDERR") return val, errors.New("valid streams are STDIN, STDOUT and STDERR")
} }
func validateAPIVersion(c *containerConfig, serverAPIVersion string) error { func validateAPIVersion(c *containerConfig, serverAPIVersion string) error {
for _, m := range c.HostConfig.Mounts { for _, m := range c.HostConfig.Mounts {
if m.BindOptions != nil && m.BindOptions.NonRecursive && versions.LessThan(serverAPIVersion, "1.40") { if m.BindOptions != nil && m.BindOptions.NonRecursive && versions.LessThan(serverAPIVersion, "1.40") {
return errors.Errorf("bind-nonrecursive requires API v1.40 or later") return errors.New("bind-nonrecursive requires API v1.40 or later")
} }
} }
return nil return nil

View file

@ -10,6 +10,7 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -21,7 +22,6 @@ import (
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
networktypes "github.com/docker/docker/api/types/network" networktypes "github.com/docker/docker/api/types/network"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
"github.com/pkg/errors"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
@ -288,7 +288,7 @@ func compareRandomizedStrings(a, b, c, d string) error {
if a == d && b == c { if a == d && b == c {
return nil return nil
} }
return errors.Errorf("strings don't match") return errors.New("strings don't match")
} }
// Simple parse with MacAddress validation // Simple parse with MacAddress validation

View file

@ -4,12 +4,12 @@ package container
import ( import (
"context" "context"
"errors"
"runtime" "runtime"
"code.forgejo.org/forgejo/runner/v9/act/common" "code.forgejo.org/forgejo/runner/v9/act/common"
"github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/system" "github.com/docker/docker/api/types/system"
"github.com/pkg/errors"
) )
// ImageExistsLocally returns a boolean indicating if an image with the // ImageExistsLocally returns a boolean indicating if an image with the

2
go.mod
View file

@ -28,7 +28,6 @@ require (
github.com/moby/patternmatcher v0.6.0 github.com/moby/patternmatcher v0.6.0
github.com/opencontainers/image-spec v1.1.1 github.com/opencontainers/image-spec v1.1.1
github.com/opencontainers/selinux v1.12.0 github.com/opencontainers/selinux v1.12.0
github.com/pkg/errors v0.9.1
github.com/rhysd/actionlint v1.7.7 github.com/rhysd/actionlint v1.7.7
github.com/sirupsen/logrus v1.9.3 github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.9.1 github.com/spf13/cobra v1.9.1
@ -82,6 +81,7 @@ require (
github.com/morikuni/aec v1.0.0 // indirect github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pjbgf/sha1cd v0.3.2 // indirect github.com/pjbgf/sha1cd v0.3.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect github.com/rivo/uniseg v0.4.7 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect