JohnSundell / Files

A nicer way to handle files & folders in Swift
MIT License
2.53k stars 182 forks source link

Try? thread exception issue with XCode 14.3 and Release #136

Open gali8 opened 1 year ago

gali8 commented 1 year ago

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.

            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:

            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.