From a462341a0a3e1132f3fcdb1efb0f7a56e851a9e1 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Fri, 29 Aug 2025 01:12:02 +0900 Subject: [PATCH] container: repeat and impossible state types This moves repeated Op errors and impossible internal state errors off of msg. Signed-off-by: Ophestra --- container/autoetc.go | 3 +-- container/autoetc_test.go | 3 +-- container/autoroot.go | 3 +-- container/autoroot_test.go | 3 +-- container/init.go | 10 ++++++++++ container/initbind.go | 2 +- container/initbind_test.go | 2 +- container/initoverlay.go | 2 +- container/initoverlay_test.go | 2 +- 9 files changed, 18 insertions(+), 12 deletions(-) diff --git a/container/autoetc.go b/container/autoetc.go index ee8dfbe..d73d275 100644 --- a/container/autoetc.go +++ b/container/autoetc.go @@ -3,7 +3,6 @@ package container import ( "encoding/gob" "fmt" - "io/fs" ) func init() { gob.Register(new(AutoEtcOp)) } @@ -24,7 +23,7 @@ func (e *AutoEtcOp) Valid() bool { return e != ni func (e *AutoEtcOp) early(*setupState, syscallDispatcher) error { return nil } func (e *AutoEtcOp) apply(state *setupState, k syscallDispatcher) error { if state.nonrepeatable&nrAutoEtc != 0 { - return msg.WrapErr(fs.ErrInvalid, "autoetc is not repeatable") + return OpRepeatError("autoetc") } state.nonrepeatable |= nrAutoEtc diff --git a/container/autoetc_test.go b/container/autoetc_test.go index 8d942f4..32513bf 100644 --- a/container/autoetc_test.go +++ b/container/autoetc_test.go @@ -2,14 +2,13 @@ package container import ( "errors" - "io/fs" "os" "testing" ) func TestAutoEtcOp(t *testing.T) { t.Run("nonrepeatable", func(t *testing.T) { - wantErr := msg.WrapErr(fs.ErrInvalid, "autoetc is not repeatable") + wantErr := OpRepeatError("autoetc") if err := (&AutoEtcOp{Prefix: "81ceabb30d37bbdb3868004629cb84e9"}).apply(&setupState{nonrepeatable: nrAutoEtc}, nil); !errors.Is(err, wantErr) { t.Errorf("apply: error = %v, want %v", err, wantErr) } diff --git a/container/autoroot.go b/container/autoroot.go index 69595c2..32b5062 100644 --- a/container/autoroot.go +++ b/container/autoroot.go @@ -3,7 +3,6 @@ package container import ( "encoding/gob" "fmt" - "io/fs" ) func init() { gob.Register(new(AutoRootOp)) } @@ -53,7 +52,7 @@ func (r *AutoRootOp) early(state *setupState, k syscallDispatcher) error { func (r *AutoRootOp) apply(state *setupState, k syscallDispatcher) error { if state.nonrepeatable&nrAutoRoot != 0 { - return msg.WrapErr(fs.ErrInvalid, "autoroot is not repeatable") + return OpRepeatError("autoroot") } state.nonrepeatable |= nrAutoRoot diff --git a/container/autoroot_test.go b/container/autoroot_test.go index fcfc3f2..13319de 100644 --- a/container/autoroot_test.go +++ b/container/autoroot_test.go @@ -2,14 +2,13 @@ package container import ( "errors" - "io/fs" "os" "testing" ) func TestAutoRootOp(t *testing.T) { t.Run("nonrepeatable", func(t *testing.T) { - wantErr := msg.WrapErr(fs.ErrInvalid, "autoroot is not repeatable") + wantErr := OpRepeatError("autoroot") if err := new(AutoRootOp).apply(&setupState{nonrepeatable: nrAutoRoot}, nil); !errors.Is(err, wantErr) { t.Errorf("apply: error = %v, want %v", err, wantErr) } diff --git a/container/init.go b/container/init.go index a13a523..8b0a7a2 100644 --- a/container/init.go +++ b/container/init.go @@ -68,6 +68,16 @@ const ( nrAutoRoot ) +// OpRepeatError is returned applying a repeated nonrepeatable [Op]. +type OpRepeatError string + +func (e OpRepeatError) Error() string { return string(e) + " is not repeatable" } + +// OpStateError indicates an impossible internal state has been reached in an [Op]. +type OpStateError string + +func (o OpStateError) Error() string { return "impossible " + string(o) + " state reached" } + // initParams are params passed from parent. type initParams struct { Params diff --git a/container/initbind.go b/container/initbind.go index bda8cb6..932095b 100644 --- a/container/initbind.go +++ b/container/initbind.go @@ -63,7 +63,7 @@ func (b *BindMountOp) apply(_ *setupState, k syscallDispatcher) error { if b.sourceFinal == nil { if b.Flags&BindOptional == 0 { // unreachable - return msg.WrapErr(os.ErrClosed, "impossible bind state reached") + return OpStateError("bind") } return nil } diff --git a/container/initbind_test.go b/container/initbind_test.go index aedbad5..38e664d 100644 --- a/container/initbind_test.go +++ b/container/initbind_test.go @@ -143,7 +143,7 @@ func TestBindMountOp(t *testing.T) { t.Run("unreachable", func(t *testing.T) { t.Run("nil sourceFinal not optional", func(t *testing.T) { - wantErr := msg.WrapErr(os.ErrClosed, "impossible bind state reached") + wantErr := OpStateError("bind") if err := new(BindMountOp).apply(nil, nil); !errors.Is(err, wantErr) { t.Errorf("apply: error = %v, want %v", err, wantErr) } diff --git a/container/initoverlay.go b/container/initoverlay.go index c913870..44c8348 100644 --- a/container/initoverlay.go +++ b/container/initoverlay.go @@ -97,7 +97,7 @@ func (o *MountOverlayOp) early(_ *setupState, k syscallDispatcher) error { if !o.ephemeral { if o.Upper != o.Work && (o.Upper == nil || o.Work == nil) { // unreachable - return msg.WrapErr(fs.ErrClosed, "impossible overlay state reached") + return OpStateError("overlay") } if o.Upper != nil { diff --git a/container/initoverlay_test.go b/container/initoverlay_test.go index 3a395f0..e12cffe 100644 --- a/container/initoverlay_test.go +++ b/container/initoverlay_test.go @@ -242,7 +242,7 @@ func TestMountOverlayOp(t *testing.T) { t.Run("unreachable", func(t *testing.T) { t.Run("nil Upper non-nil Work not ephemeral", func(t *testing.T) { - wantErr := msg.WrapErr(fs.ErrClosed, "impossible overlay state reached") + wantErr := OpStateError("overlay") if err := (&MountOverlayOp{ Work: MustAbs("/"), }).early(nil, nil); !errors.Is(err, wantErr) {