container icon indicating copy to clipboard operation
container copied to clipboard

fix: replace try! with try for createDirectory in SystemStart

Open kapil971390 opened this issue 5 months ago • 1 comments

Fixes #1802.

run() in SystemStart.swift is async throws, and every other filesystem and configuration call in it propagates errors with plain try. Line 107 was the exception — a try! on FileManager.default.createDirectory that crashes with a fatal error if the app-root directory isn't writable, instead of surfacing a clean error message.

Before:

ContainerCommands/SystemStart.swift:107: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=513 "You don't have permission to save the file "apiserver" in the folder "test-approot"." ...

exit code 133 (abort)

After:

Error: You don't have permission to save the file "apiserver" in the folder "test-approot".

exit code 1

One character change: try! → try.

Reproduce:

rm -rf test-data && make APP_ROOT=test-data all
mkdir -p /tmp/test-approot && chmod 555 /tmp/test-approot
bin/container system start --app-root /tmp/test-approot

Tested on macOS 26.5.1, Swift 6.2.4, commit 1d70dd6.

kapil971390 avatar Jun 24 '26 19:06 kapil971390

apple-container-system-start-crash Crash output from reproduce run (before fix):

ContainerCommands/SystemStart.swift:107: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=513 "You don't have permission to save the file "apiserver" in the folder "test-approot"." UserInfo={NSFilePath=/tmp/test-approot/apiserver, NSURL=file:///tmp/test-approot/apiserver, NSUnderlyingError=0x10836cbc0 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}

After fix:

Error: You don't have permission to save the file "apiserver" in the folder "test-approot".

exit code 1, no crash.

kapil971390 avatar Jun 24 '26 19:06 kapil971390

Hi @kapil971390, thank you for the fix! We've already merged an earlier PR for this: #1785.

jglogan avatar Jun 26 '26 04:06 jglogan