Code-Hex / vz

Create virtual machines and run Linux-based operating systems in Go using Apple Virtualization.framework.

Home Page:https://pkg.go.dev/github.com/Code-Hex/vz/v3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught exception when running `virtualization` example program

cfergeau opened this issue · comments

With master, if I run the linux virtualization example without setting any of the required env vars, I'm getting this failure:

% ./virtualization 
2022-09-08 12:11:46.146 virtualization[37825:952616] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[VZLinuxBootLoader initWithKernelURL:]: The URL (null) is not a file URL'
*** First throw call stack:
(
	0   CoreFoundation                      0x00000001891711a8 __exceptionPreprocess + 240
	1   libobjc.A.dylib                     0x0000000188ebbe04 objc_exception_throw + 60
	2   CoreFoundation                      0x0000000189170ff4 +[NSException exceptionWithName:reason:userInfo:] + 0
	3   Virtualization                      0x00000001ef375478 _ZN2Vz32raise_invalid_argument_exceptionEP11objc_objectP13objc_selectorP8NSStringz + 176
	4   Virtualization                      0x00000001ef2b963c _ZN2Vz20validate_is_file_urlEP5NSURLP11objc_objectP13objc_selector + 96
	5   Virtualization                      0x00000001ef33b8e8 -[VZLinuxBootLoader initWithKernelURL:] + 56
	6   virtualization                      0x00000001041a59d8 newVZLinuxBootLoader + 104
	7   virtualization                      0x00000001041a40a0 _cgo_16e5e8d7eb11_Cfunc_newVZLinuxBootLoader + 36
	8   virtualization                      0x00000001040f48ec runtime.asmcgocall.abi0 + 124
)
libc++abi: terminating with uncaught exception of type NSException
SIGABRT: abort
PC=0x188feed98 m=0 sigcode=0
signal arrived during cgo execution

VZLinuxBootLoader initWithKernelURL throws an exception because we pass it a null/empty URL, but nothing is catching this exception, so the application gets killed. It would be a lot nicer if calling VZLinuxBootLoader initWithKernelURL with invalid arguments would return a regular go error.

@cfergeau Thanks for your reporting!

Exactly, we should handle them

Maybe it's possible to get other exceptions from these methods? The current fix avoids 'file not found' exceptions. There will still be crashes if an exception is raised for another reason.