diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-06-08 14:19:11 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-06-08 14:58:24 +0900 |
| commit | f869ff95a12756de97827b4afd93763f9661f144 (patch) | |
| tree | 6f5445ae623f44ceb99c8f7ddb5bb4cd1fb04aa0 /container | |
| parent | 725f2e0ef3eaba1ad46b597604a684125ab93911 (diff) | |
all: apply modernisers
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container')
| -rw-r--r-- | container/container.go | 7 | ||||
| -rw-r--r-- | container/dispatcher_test.go | 2 | ||||
| -rw-r--r-- | container/errors.go | 14 | ||||
| -rw-r--r-- | container/init_test.go | 16 |
4 files changed, 16 insertions, 23 deletions
diff --git a/container/container.go b/container/container.go index 8af77315..3571d04a 100644 --- a/container/container.go +++ b/container/container.go @@ -154,11 +154,8 @@ func (e *StartError) Error() string { return e.Step } - { - var syscallError *os.SyscallError - if errors.As(e.Err, &syscallError) && syscallError != nil { - return e.Step + " " + syscallError.Error() - } + if se, ok := errors.AsType[*os.SyscallError](e.Err); ok && se != nil { + return e.Step + " " + se.Error() } return e.Step + ": " + e.Err.Error() diff --git a/container/dispatcher_test.go b/container/dispatcher_test.go index 49631854..242af1bf 100644 --- a/container/dispatcher_test.go +++ b/container/dispatcher_test.go @@ -235,8 +235,6 @@ func checkOpBehaviour(t *testing.T, testCases []opBehaviourTestCase) { }) } -func sliceAddr[S any](s []S) *[]S { return &s } - func newCheckedFile(t *testing.T, name, wantData string, closeErr error) osFile { f := &checkedOsFile{t: t, name: name, want: wantData, closeErr: closeErr} // check happens in Close, and cleanup is not guaranteed to run, so relying diff --git a/container/errors.go b/container/errors.go index 5a67bb4c..053bdeb7 100644 --- a/container/errors.go +++ b/container/errors.go @@ -46,9 +46,8 @@ func messageFromError(err error) (m string, ok bool) { // While this is usable for pointer errors, such use should be avoided as nil // check is omitted. func messagePrefix[T error](prefix string, err error) (string, bool) { - var targetError T - if errors.As(err, &targetError) { - return prefix + targetError.Error(), true + if e, ok := errors.AsType[T](err); ok { + return prefix + e.Error(), true } return zeroString, false } @@ -58,9 +57,8 @@ func messagePrefixP[V any, T interface { *V error }](prefix string, err error) (string, bool) { - var targetError T - if errors.As(err, &targetError) && targetError != nil { - return prefix + targetError.Error(), true + if e, ok := errors.AsType[T](err); ok && e != nil { + return prefix + e.Error(), true } return zeroString, false } @@ -109,8 +107,8 @@ func optionalErrorUnwrap(err error) error { // errnoFallback returns the concrete errno from an error, or a [os.PathError] fallback. func errnoFallback(op, path string, err error) (syscall.Errno, *os.PathError) { - var errno syscall.Errno - if !errors.As(err, &errno) { + errno, ok := errors.AsType[syscall.Errno](err) + if !ok { return 0, &os.PathError{Op: op, Path: path, Err: err} } return errno, nil diff --git a/container/init_test.go b/container/init_test.go index 23d0a7b3..fe0e627a 100644 --- a/container/init_test.go +++ b/container/init_test.go @@ -95,7 +95,7 @@ func TestInitEntrypoint(t *testing.T) { Uid: 1 << 16, Gid: 1 << 15, Hostname: "hakurei-check", - Ops: (*Ops)(sliceAddr(make(Ops, 1))), + Ops: new(make(Ops, 1)), SeccompRules: make([]std.NativeRule, 0), SeccompPresets: std.PresetStrict, RetainSession: true, @@ -123,7 +123,7 @@ func TestInitEntrypoint(t *testing.T) { Uid: 1 << 16, Gid: 1 << 15, Hostname: "hakurei-check", - Ops: (*Ops)(sliceAddr(make(Ops, 1))), + Ops: new(make(Ops, 1)), SeccompRules: make([]std.NativeRule, 0), SeccompPresets: std.PresetStrict, RetainSession: true, @@ -152,7 +152,7 @@ func TestInitEntrypoint(t *testing.T) { Uid: 1 << 16, Gid: 1 << 15, Hostname: "hakurei-check", - Ops: (*Ops)(sliceAddr(make(Ops, 1))), + Ops: new(make(Ops, 1)), SeccompRules: make([]std.NativeRule, 0), SeccompPresets: std.PresetStrict, RetainSession: true, @@ -182,7 +182,7 @@ func TestInitEntrypoint(t *testing.T) { Uid: 1 << 16, Gid: 1 << 15, Hostname: "hakurei-check", - Ops: (*Ops)(sliceAddr(make(Ops, 1))), + Ops: new(make(Ops, 1)), SeccompRules: make([]std.NativeRule, 0), SeccompPresets: std.PresetStrict, RetainSession: true, @@ -213,7 +213,7 @@ func TestInitEntrypoint(t *testing.T) { Uid: 1 << 16, Gid: 1 << 15, Hostname: "hakurei-check", - Ops: (*Ops)(sliceAddr(make(Ops, 1))), + Ops: new(make(Ops, 1)), SeccompRules: make([]std.NativeRule, 0), SeccompPresets: std.PresetStrict, RetainSession: true, @@ -245,7 +245,7 @@ func TestInitEntrypoint(t *testing.T) { Uid: 1 << 16, Gid: 1 << 15, Hostname: "hakurei-check", - Ops: (*Ops)(sliceAddr(make(Ops, 1))), + Ops: new(make(Ops, 1)), SeccompRules: make([]std.NativeRule, 0), SeccompPresets: std.PresetStrict, RetainSession: true, @@ -279,7 +279,7 @@ func TestInitEntrypoint(t *testing.T) { Uid: 1 << 16, Gid: 1 << 15, Hostname: "hakurei-check", - Ops: (*Ops)(sliceAddr(make(Ops, 1))), + Ops: new(make(Ops, 1)), SeccompRules: make([]std.NativeRule, 0), SeccompPresets: std.PresetStrict, RetainSession: true, @@ -315,7 +315,7 @@ func TestInitEntrypoint(t *testing.T) { Uid: 1 << 16, Gid: 1 << 15, Hostname: "hakurei-check", - Ops: (*Ops)(sliceAddr(make(Ops, 1))), + Ops: new(make(Ops, 1)), SeccompRules: make([]std.NativeRule, 0), SeccompPresets: std.PresetStrict, RetainSession: true, |
