JohnSundell / Files

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

Capturing the underlying error #40

Closed ghost closed 6 years ago

ghost commented 6 years ago

Let me know your thoughts on this change. I'm happy to change styling, naming etc.

ghost commented 6 years ago

Hmmm it looks like CI won't fire. Maybe I should have re-opened this pull request, before pushing. Will try pushing an empty commit.

ghost commented 6 years ago

CI failing. Sources/Files.swift:740:17: error: switch must be exhaustive

public static func ==(lhs: FolderOperationError, rhs: FolderOperationError) -> Bool {
    switch lhs {
    case .createFailed(let errorA as NSError):
        switch rhs {
        case .createFailed(let errorB as NSError):
            return errorA.domain == errorB.domain && errorA.code == errorB.code
        }
    }
}

Build passes locally. Strange. I assume it's not exhaustive because the error could be some other type. Will take another look.

ghost commented 6 years ago

Do we need to set errors as optionals?

Example here

enum RenameError: Error, Equatable, CustomStringConvertible {
        case parentFolderMissing
        case other(Error?)
}

It's not consistent at the moment.

enum ItemOperationError: Error, Equatable, CustomStringConvertible {
        case copyFailed(Item, Error)
        case deleteFailed(Item, Error?)
}

What's your opinion on errors being optional? Will there be an NSFileManager error that is nil ? Should we anticipate that?

ghost commented 6 years ago

Well I guess the CI build failing answers part of my question.

error: cannot downcast from 'Error' to a more optional type 'NSError?'

Why don't I see this error locally???

ghost commented 6 years ago

CI failing

Test Case 'FilesTests.testCreatingAndDeletingFile' started at 2017-11-16 10:15:46.233
/home/travis/build/JohnSundell/Files/Tests/FilesTests/FilesTests.swift:667: error: FilesTests.testCreatingAndDeletingFile : XCTAssertEqual failed: ("Failed to read file. Error: Optional(The operation could not be completed).") is not equal to ("Failed to read file. Error: Optional(The operation could not be completed).") - 
Test Case 'FilesTests.testCreatingAndDeletingFile' failed (0.002 seconds)
Test Case 'FilesTests.testCreatingAndDeletingFolder' started at 2017-11-16 10:15:46.235
/home/travis/build/JohnSundell/Files/Tests/FilesTests/FilesTests.swift:667: error: FilesTests.testCreatingAndDeletingFolder : XCTAssertEqual failed: ("Failed to read file. Error: Optional(The operation could not be completed).") is not equal to ("Failed to read file. Error: Optional(The operation could not be completed).") - 
Test Case 'FilesTests.testCreatingAndDeletingFolder' failed (0.001 seconds)

Passes for me locally ?!?!?!

ghost commented 6 years ago

"The operation could not be completed" doesn't sound like NSError(domain: NSCocoaErrorDomain, code: 260, userInfo: nil)

This might be a code mismatch error between platforms. Maybe code 260 is something else outside of iOS.

ghost commented 6 years ago

Tests all fire locally for iOS, macOS and tvOS. I wonder if travis handles other platforms. Your deploying to Linux right? I wonder if that environment uses the same error domain/code system.

ghost commented 6 years ago

Or is this about comparing optionals?

ghost commented 6 years ago

Some issue??? Looks like it's still using optionals?

Test Case 'FilesTests.testCreatingAndDeletingFile' started at 2017-11-16 10:37:53.851
/home/travis/build/JohnSundell/Files/Tests/FilesTests/FilesTests.swift:667: error: FilesTests.testCreatingAndDeletingFile : XCTAssertEqual failed: ("Failed to read file. Error: Optional(The operation could not be completed).") is not equal to ("Failed to read file. Error: Optional(The operation could not be completed).") - 
Test Case 'FilesTests.testCreatingAndDeletingFile' failed (0.002 seconds)
Test Case 'FilesTests.testCreatingAndDeletingFolder' started at 2017-11-16 10:37:53.853
/home/travis/build/JohnSundell/Files/Tests/FilesTests/FilesTests.swift:667: error: FilesTests.testCreatingAndDeletingFolder : XCTAssertEqual failed: ("Failed to read file. Error: Optional(The operation could not be completed).") is not equal to ("Failed to read file. Error: Optional(The operation could not be completed).") - 
Test Case 'FilesTests.testCreatingAndDeletingFolder' failed (0.001 seconds)

Maybe it's an issue with travis at the moment.

W: Some index files failed to download. They have been ignored, or old ones used instead.

Sigh

ghost commented 6 years ago

All tests pass locally. Not sure why travis is upset. Will wait to hear from you.

ghost commented 6 years ago

Baahhhhh !

Test Case 'FilesTests.testCreatingAndDeletingFile' started at 2017-11-16 11:38:50.496
/home/travis/build/JohnSundell/Files/Tests/FilesTests/FilesTests.swift:667: error: FilesTests.testCreatingAndDeletingFile : XCTAssertEqual failed: ("Failed to read file. Error: The operation could not be completed.") is not equal to ("Failed to read file. Error: The operation could not be completed.") - 
Test Case 'FilesTests.testCreatingAndDeletingFile' failed (0.002 seconds)
Test Case 'FilesTests.testCreatingAndDeletingFolder' started at 2017-11-16 11:38:50.498
/home/travis/build/JohnSundell/Files/Tests/FilesTests/FilesTests.swift:667: error: FilesTests.testCreatingAndDeletingFolder : XCTAssertEqual failed: ("Failed to read file. Error: The operation could not be completed.") is not equal to ("Failed to read file. Error: The operation could not be completed.") - 
Test Case 'FilesTests.testCreatingAndDeletingFolder' failed (0.001 seconds)
JohnSundell commented 6 years ago

Hi @rob-nash 👋 Thanks for this PR! I'll have a look at it in the coming week and will try to help you resolve the Linux CI problem 👍