diff --git a/container/errors.go b/container/errors.go index 8d8ad49..f4198b0 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 f99812b..df69c4b 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 6b134ce..fd7ac72 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 cf21e81..1d401d9 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 4a436ab..fca32c6 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 7184b0b..746e70f 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) } })