container/mount: unwrap vfs decoder errors
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Test / Create distribution (push) Successful in 36s
				
			
		
			
				
	
				Test / Sandbox (push) Successful in 2m6s
				
			
		
			
				
	
				Test / Hakurei (push) Successful in 3m21s
				
			
		
			
				
	
				Test / Hpkg (push) Successful in 3m40s
				
			
		
			
				
	
				Test / Sandbox (race detector) (push) Successful in 4m32s
				
			
		
			
				
	
				Test / Hakurei (race detector) (push) Successful in 5m19s
				
			
		
			
				
	
				Test / Flake checks (push) Successful in 1m36s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Test / Create distribution (push) Successful in 36s
				
			Test / Sandbox (push) Successful in 2m6s
				
			Test / Hakurei (push) Successful in 3m21s
				
			Test / Hpkg (push) Successful in 3m40s
				
			Test / Sandbox (race detector) (push) Successful in 4m32s
				
			Test / Hakurei (race detector) (push) Successful in 5m19s
				
			Test / Flake checks (push) Successful in 1m36s
				
			These are now handled by init. This eliminates generic WrapErr from mount and procPaths. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
		
							parent
							
								
									d7c7c69a13
								
							
						
					
					
						commit
						08eeafe817
					
				| @ -4,17 +4,19 @@ import ( | |||||||
| 	"errors" | 	"errors" | ||||||
| 	"os" | 	"os" | ||||||
| 	"syscall" | 	"syscall" | ||||||
|  | 
 | ||||||
|  | 	"hakurei.app/container/vfs" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // messageFromError returns a printable error message for a supported concrete type. | // messageFromError returns a printable error message for a supported concrete type. | ||||||
| func messageFromError(err error) (string, bool) { | 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 | 		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 | 		return m, ok | ||||||
| 	} | 	} | ||||||
| 	if m, ok := messagePrefixP[AbsoluteError, *AbsoluteError]("", err); ok { | 	if m, ok := messagePrefixP[AbsoluteError]("", err); ok { | ||||||
| 		return m, ok | 		return m, ok | ||||||
| 	} | 	} | ||||||
| 	if m, ok := messagePrefix[OpRepeatError]("", err); ok { | 	if m, ok := messagePrefix[OpRepeatError]("", err); ok { | ||||||
| @ -24,6 +26,9 @@ func messageFromError(err error) (string, bool) { | |||||||
| 		return m, ok | 		return m, ok | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	if m, ok := messagePrefixP[vfs.DecoderError]("cannot ", err); ok { | ||||||
|  | 		return m, ok | ||||||
|  | 	} | ||||||
| 	if m, ok := messagePrefix[TmpfsSizeError]("", err); ok { | 	if m, ok := messagePrefix[TmpfsSizeError]("", err); ok { | ||||||
| 		return m, ok | 		return m, ok | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -4,8 +4,11 @@ import ( | |||||||
| 	"errors" | 	"errors" | ||||||
| 	"os" | 	"os" | ||||||
| 	"reflect" | 	"reflect" | ||||||
|  | 	"strconv" | ||||||
| 	"syscall" | 	"syscall" | ||||||
| 	"testing" | 	"testing" | ||||||
|  | 
 | ||||||
|  | 	"hakurei.app/container/vfs" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func TestMessageFromError(t *testing.T) { | func TestMessageFromError(t *testing.T) { | ||||||
| @ -39,6 +42,9 @@ func TestMessageFromError(t *testing.T) { | |||||||
| 		{"state", OpStateError("overlay"), | 		{"state", OpStateError("overlay"), | ||||||
| 			"impossible overlay state reached", true}, | 			"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", TmpfsSizeError(-1), | ||||||
| 			"tmpfs size -1 out of bounds", true}, | 			"tmpfs size -1 out of bounds", true}, | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -149,12 +149,7 @@ func (p *procPaths) remount(target string, flags uintptr) error { | |||||||
| 	return p.mountinfo(func(d *vfs.MountInfoDecoder) error { | 	return p.mountinfo(func(d *vfs.MountInfoDecoder) error { | ||||||
| 		n, err := d.Unfold(targetKFinal) | 		n, err := d.Unfold(targetKFinal) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			if errors.As(err, new(vfs.UnfoldTargetError)) { | 			return err | ||||||
| 				return msg.WrapErr(err, |  | ||||||
| 					fmt.Sprintf("mount point %q never appeared in mountinfo", targetKFinal)) |  | ||||||
| 			} |  | ||||||
| 			return wrapErrSuffix(err, |  | ||||||
| 				"cannot unfold mount hierarchy:") |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if err = remountWithFlags(p.k, n, mf); err != nil { | 		if err = remountWithFlags(p.k, n, mf); err != nil { | ||||||
|  | |||||||
| @ -118,7 +118,7 @@ func TestRemount(t *testing.T) { | |||||||
| 			{"readlink", expectArgs{"/host/proc/self/fd/3735928559"}, "/sysroot/.hakurei", nil}, | 			{"readlink", expectArgs{"/host/proc/self/fd/3735928559"}, "/sysroot/.hakurei", nil}, | ||||||
| 			{"close", expectArgs{0xdeadbeef}, nil, nil}, | 			{"close", expectArgs{0xdeadbeef}, nil, nil}, | ||||||
| 			{"openNew", expectArgs{"/host/proc/self/mountinfo"}, newConstFile(sampleMountinfoNix), 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 { | 		{"mountinfo", func(k syscallDispatcher) error { | ||||||
| 			return newProcPaths(k, hostPath).remount("/sysroot/nix", syscall.MS_REC|syscall.MS_RDONLY|syscall.MS_NODEV) | 			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}, | 			{"readlink", expectArgs{"/host/proc/self/fd/3735928559"}, "/sysroot/nix", nil}, | ||||||
| 			{"close", expectArgs{0xdeadbeef}, nil, nil}, | 			{"close", expectArgs{0xdeadbeef}, nil, nil}, | ||||||
| 			{"openNew", expectArgs{"/host/proc/self/mountinfo"}, newConstFile("\x00"), 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 { | 		{"mount", func(k syscallDispatcher) error { | ||||||
| 			return newProcPaths(k, hostPath).remount("/sysroot/nix", syscall.MS_REC|syscall.MS_RDONLY|syscall.MS_NODEV) | 			return newProcPaths(k, hostPath).remount("/sysroot/nix", syscall.MS_REC|syscall.MS_RDONLY|syscall.MS_NODEV) | ||||||
|  | |||||||
| @ -152,8 +152,7 @@ func (p *procPaths) mountinfo(f func(d *vfs.MountInfoDecoder) error) error { | |||||||
| 		if err = r.Close(); err != nil { | 		if err = r.Close(); err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} else if err = d.Err(); err != nil { | 		} else if err = d.Err(); err != nil { | ||||||
| 			return wrapErrSuffix(err, | 			return err | ||||||
| 				"cannot parse mountinfo:") |  | ||||||
| 		} | 		} | ||||||
| 		return err0 | 		return err0 | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -1,7 +1,6 @@ | |||||||
| package container | package container | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"errors" |  | ||||||
| 	"io" | 	"io" | ||||||
| 	"math" | 	"math" | ||||||
| 	"os" | 	"os" | ||||||
| @ -248,8 +247,8 @@ func TestProcPaths(t *testing.T) { | |||||||
| 					t.Fatalf("WriteFile: error = %v", err) | 					t.Fatalf("WriteFile: error = %v", err) | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				wantErr := wrapErrSuffix(&vfs.DecoderError{Op: "parse", Line: 0, Err: vfs.ErrMountInfoFields}, "cannot parse mountinfo:") | 				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)) }); !errors.Is(err, wantErr) { | 				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) | 					t.Fatalf("mountinfo: error = %v, want %v", err, wantErr) | ||||||
| 				} | 				} | ||||||
| 			}) | 			}) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user