apple / apple/container

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

Open Beginner friendly
#1,802 1 comment 0 reactions 0 assignees View on GitHub
stability
Dominant language
Swift
Stars
49.9k
Forks
1.8k
Avg merge
1d 20h
Merged PRs (30d)
22

Description

**I have done the following**

- [x] I have searched the existing issues
- [x] If possible, I've reproduced the issue using the 'main' branch of this project

## Steps to reproduce

1. Build from source on main (`1d70dd6`):
```
rm -rf test-data && make APP_ROOT=test-data all
```
2. Create a read-only app-root directory:
```
mkdir -p /tmp/test-approot && chmod 555 /tmp/test-approot
```
3. Run:
```
bin/container system start --app-root /tmp/test-approot
```

## Current behavior

The process crashes with a fatal error and exit code 133:

```
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"}}
```

The crash is at line 107 of `SystemStart.swift` — a `try!` on `FileManager.default.createDirectory`. `run()` is already `async throws`, and every other call in the same function uses plain `try` and propagates errors normally. This one line does not.

## Expected behavior

`container system start` should surface a clear error and exit cleanly — the same way every other failure in `run()` does.

## Relevant log output

```
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"}}
```

## Environment

- OS: macOS 26.5.1 (25F80)
- Xcode: Version 26.0 (17A324)
- Swift: Apple Swift version 6.2.4 (swiftlang-6.2.4.1.4 clang-1700.6.4.2)
- Commit: `1d70dd6` (main)
- Build: debug (`make APP_ROOT=test-data all`)

Contributor guide

Open the contributing guide

Research direction

Open ContainerCommands/SystemStart.swift and inspect the createDirectory call at line 107 within run(). Reproduce the issue with a read-only app-root using the commands in the report, then verify that container system start reports a clear error and exits cleanly instead of crashing with a fatal error.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli
Issue type
Bug
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.