Skip to content

fix: replace try! with try for createDirectory in SystemStart#1803

Closed
kapil971390 wants to merge 1 commit into
apple:mainfrom
kapil971390:fix/system-start-try-force-unwrap
Closed

fix: replace try! with try for createDirectory in SystemStart#1803
kapil971390 wants to merge 1 commit into
apple:mainfrom
kapil971390:fix/system-start-try-force-unwrap

Conversation

@kapil971390

Copy link
Copy Markdown

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

kapil971390 commented Jun 24, 2026

Copy link
Copy Markdown
Author
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.

FileManager.createDirectory can fail when the app-root is not writable
(e.g. wrong permissions, read-only filesystem). run() is already
async throws and every other call in the function propagates errors
with plain try — this one line was the exception.

Fixes apple#1802
@kapil971390 kapil971390 force-pushed the fix/system-start-try-force-unwrap branch from d688367 to 8d0d7f6 Compare June 24, 2026 19:16
@jglogan

jglogan commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

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

@jglogan jglogan closed this Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: container system start crashes with fatal error when app-root directory is not writable

2 participants