JohnSundell / JohnSundell/Files

Try? thread exception issue with XCode 14.3 and Release

Open
#136 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
2.6k
Forks
197
PR merge metrics
No merged PRs in 30d

Description

I found an issue with XCode 14.3 on iOS when the build configuration (in schema) or archive are in Release.
No issues on XCode 14.2 or Debug.

Look the example below.

fileProfile and folderDevice are with "try?". Both are nil because both not exist.
the do/catch doesn't throws an exception instead a thread exception into the AppDelegate appears.

```swift
let filePathProfile = Const.LOCAL_PATH_PROFILE // is /var/..../file.jpg
let filePathDevice = Const.LOCAL_PATH_DEVICES_ROOT // is /var/..../folder

let fileProfile = try? File(path: filePathProfile)
let folderDevice = try? Folder(path: filePathDevice)

do {
try fileProfile?.delete()
try folderDevice?.delete()
}
catch {
debugPrint("\(error.localizedDescription)")
}
```

The issue not appear and the exception LocationErrorReason.emptyFilePath is correctly thrown if:
- try? is replaced with try
- ?.delete() is replaced with .delete()
- the two "let..." rows are moved into the do/catch

```swift
let filePathProfile = Const.LOCAL_PATH_PROFILE // is /var/..../file.jpg
let filePathDevice = Const.LOCAL_PATH_DEVICES_ROOT // is /var/..../folder

do {
let fileProfile = try File(path: filePathProfile)
let folderDevice = try Folder(path: filePathDevice)

try fileProfile.delete()
try folderDevice.delete()
}
catch {
debugPrint("\(error.localizedDescription)")
}
```

I don't know if the issue is caused by File, Folder or both.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.