aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-08-29 22:15:05 +0900
committerOphestra <cat@gensokyo.uk>2025-08-29 22:15:05 +0900
commit08eeafe8174efed2414d66788a927168efeba691 (patch)
tree966ab2b3abec177ee3eaeac777b4b636a32261df
parentd7c7c69a13868546c26c3e5096fca09304a6e182 (diff)
container/mount: unwrap vfs decoder errors
These are now handled by init. This eliminates generic WrapErr from mount and procPaths. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--container/errors.go11
-rw-r--r--container/errors_test.go6
-rw-r--r--container/mount.go7
-rw-r--r--container/mount_test.go4
-rw-r--r--container/path.go3
-rw-r--r--container/path_test.go5
6 files changed, 20 insertions, 16 deletions
diff --git a/container/errors.go b/container/errors.go
index 8d8ad492..f4198b09 100644
--- a/container/errors.go
+++ b/container/errors.go
@@ -4,17 +4,19 @@ import (
"errors"
"os"
"syscall"
+
+ "hakurei.app/container/vfs"
)
// messageFromError returns a printable error message for a supported concrete type.
func messageFromError(err error) (string, bool) {
- if m, ok := messagePrefixP[MountError, *MountError]("cannot ", err); ok {
+ if m, ok := messagePrefixP[MountError]("cannot ", err); ok {
return m, ok
}
- if m, ok := messagePrefixP[os.PathError, *os.PathError]("cannot ", err); ok {
+ if m, ok := messagePrefixP[os.PathError]("cannot ", err); ok {
return m, ok
}
- if m, ok := messagePrefixP[AbsoluteError, *AbsoluteError]("", err); ok {
+ if m, ok := messagePrefixP[AbsoluteError]("", err); ok {
return m, ok
}
if m, ok := messagePrefix[OpRepeatError]("", err); ok {
@@ -24,6 +26,9 @@ func messageFromError(err error) (string, bool) {
return m, ok
}
+ if m, ok := messagePrefixP[vfs.DecoderError]("cannot ", err); ok {
+ return m, ok
+ }
if m, ok := messagePrefix[TmpfsSizeError]("", err); ok {
return m, ok
}
diff --git a/container/errors_test.go b/container/errors_test.go
index f99812b8..df69c4b1 100644
--- a/container/errors_test.go
+++ b/container/errors_test.go
@@ -4,8 +4,11 @@ import (
"errors"
"os"
"reflect"
+ "strconv"
"syscall"
"testing"
+
+ "hakurei.app/container/vfs"
)
func TestMessageFromError(t *testing.T) {
@@ -39,6 +42,9 @@ func TestMessageFromError(t *testing.T) {
{"state", OpStateError("overlay"),
"impossible overlay state reached", true},
+ {"vfs parse", &vfs.DecoderError{Op: "parse", Line: 0xdeadbeef, Err: &strconv.NumError{Func: "Atoi", Num: "meow", Err: strconv.ErrSyntax}},
+ `cannot parse mountinfo at line 3735928559: numeric field "meow" invalid syntax`, true},
+
{"tmpfs", TmpfsSizeError(-1),
"tmpfs size -1 out of bounds", true},
diff --git a/container/mount.go b/container/mount.go
index 6b134ce4..fd7ac723 100644
--- a/container/mount.go
+++ b/container/mount.go
@@ -149,12 +149,7 @@ func (p *procPaths) remount(target string, flags uintptr) error {
return p.mountinfo(func(d *vfs.MountInfoDecoder) error {
n, err := d.Unfold(targetKFinal)
if err != nil {
- if errors.As(err, new(vfs.UnfoldTargetError)) {
- return msg.WrapErr(err,
- fmt.Sprintf("mount point %q never appeared in mountinfo", targetKFinal))
- }
- return wrapErrSuffix(err,
- "cannot unfold mount hierarchy:")
+ return err
}
if err = remountWithFlags(p.k, n, mf); err != nil {
diff --git a/container/mount_test.go b/container/mount_test.go
index cf21e81f..1d401d92 100644
--- a/container/mount_test.go
+++ b/container/mount_test.go
@@ -118,7 +118,7 @@ func TestRemount(t *testing.T) {
{"readlink", expectArgs{"/host/proc/self/fd/3735928559"}, "/sysroot/.hakurei", nil},
{"close", expectArgs{0xdeadbeef}, nil, nil},
{"openNew", expectArgs{"/host/proc/self/mountinfo"}, newConstFile(sampleMountinfoNix), nil},
- }}, msg.WrapErr(&vfs.DecoderError{Op: "unfold", Line: -1, Err: vfs.UnfoldTargetError("/sysroot/.hakurei")}, `mount point "/sysroot/.hakurei" never appeared in mountinfo`)},
+ }}, &vfs.DecoderError{Op: "unfold", Line: -1, Err: vfs.UnfoldTargetError("/sysroot/.hakurei")}},
{"mountinfo", func(k syscallDispatcher) error {
return newProcPaths(k, hostPath).remount("/sysroot/nix", syscall.MS_REC|syscall.MS_RDONLY|syscall.MS_NODEV)
@@ -128,7 +128,7 @@ func TestRemount(t *testing.T) {
{"readlink", expectArgs{"/host/proc/self/fd/3735928559"}, "/sysroot/nix", nil},
{"close", expectArgs{0xdeadbeef}, nil, nil},
{"openNew", expectArgs{"/host/proc/self/mountinfo"}, newConstFile("\x00"), nil},
- }}, wrapErrSuffix(&vfs.DecoderError{Op: "parse", Line: 0, Err: vfs.ErrMountInfoFields}, `cannot parse mountinfo:`)},
+ }}, &vfs.DecoderError{Op: "parse", Line: 0, Err: vfs.ErrMountInfoFields}},
{"mount", func(k syscallDispatcher) error {
return newProcPaths(k, hostPath).remount("/sysroot/nix", syscall.MS_REC|syscall.MS_RDONLY|syscall.MS_NODEV)
diff --git a/container/path.go b/container/path.go
index 4a436abf..fca32c66 100644
--- a/container/path.go
+++ b/container/path.go
@@ -152,8 +152,7 @@ func (p *procPaths) mountinfo(f func(d *vfs.MountInfoDecoder) error) error {
if err = r.Close(); err != nil {
return err
} else if err = d.Err(); err != nil {
- return wrapErrSuffix(err,
- "cannot parse mountinfo:")
+ return err
}
return err0
}
diff --git a/container/path_test.go b/container/path_test.go
index 7184b0bf..746e70fe 100644
--- a/container/path_test.go
+++ b/container/path_test.go
@@ -1,7 +1,6 @@
package container
import (
- "errors"
"io"
"math"
"os"
@@ -248,8 +247,8 @@ func TestProcPaths(t *testing.T) {
t.Fatalf("WriteFile: error = %v", err)
}
- wantErr := wrapErrSuffix(&vfs.DecoderError{Op: "parse", Line: 0, Err: vfs.ErrMountInfoFields}, "cannot parse mountinfo:")
- if err := newProcPaths(direct{}, tempDir).mountinfo(func(d *vfs.MountInfoDecoder) error { return d.Decode(new(*vfs.MountInfo)) }); !errors.Is(err, wantErr) {
+ wantErr := &vfs.DecoderError{Op: "parse", Line: 0, Err: vfs.ErrMountInfoFields}
+ if err := newProcPaths(direct{}, tempDir).mountinfo(func(d *vfs.MountInfoDecoder) error { return d.Decode(new(*vfs.MountInfo)) }); !reflect.DeepEqual(err, wantErr) {
t.Fatalf("mountinfo: error = %v, want %v", err, wantErr)
}
})