{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/2451","labels_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2451/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2451/comments","events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2451/events","html_url":"https://github.com/realm/realm-cocoa/pull/2451","id":103478129,"number":2451,"title":"Allow to catch RLMError cases by ErrorType wrapper","user":{"login":"mrackwitz","id":1389011,"avatar_url":"https://avatars.githubusercontent.com/u/1389011?v=3","gravatar_id":"","url":"https://api.github.com/users/mrackwitz","html_url":"https://github.com/mrackwitz","followers_url":"https://api.github.com/users/mrackwitz/followers","following_url":"https://api.github.com/users/mrackwitz/following{/other_user}","gists_url":"https://api.github.com/users/mrackwitz/gists{/gist_id}","starred_url":"https://api.github.com/users/mrackwitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrackwitz/subscriptions","organizations_url":"https://api.github.com/users/mrackwitz/orgs","repos_url":"https://api.github.com/users/mrackwitz/repos","events_url":"https://api.github.com/users/mrackwitz/events{/privacy}","received_events_url":"https://api.github.com/users/mrackwitz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-cocoa/labels/pr","name":"pr","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-27T10:40:57Z","updated_at":"2015-08-31T08:23:14Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/realm/realm-cocoa/pulls/2451","html_url":"https://github.com/realm/realm-cocoa/pull/2451","diff_url":"https://github.com/realm/realm-cocoa/pull/2451.diff","patch_url":"https://github.com/realm/realm-cocoa/pull/2451.patch"},"body":"Even though `RLMError` is accessible as Swift enumeration, it is based on integer as type and can only be based on a literal type in Objective-C. At the moment, you would need to go over `NSError` to catch  errors from Swift. This PR introduces a wrapper for improved user convenience, which allows to retrieve `ErrorType` compatible instances. They should be used exclusively for the cause of comparison in `do { … } catch Realm.Error.X { … }` statements.\r\n\r\n#### ToDos:\r\n\r\n* [ ] Adopt error handling in unit tests\r\n* [ ] Make use of them in unit tests\r\n"},"comment":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/comments/136298382","html_url":"https://github.com/realm/realm-cocoa/pull/2451#issuecomment-136298382","issue_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2451","id":136298382,"user":{"login":"mrackwitz","id":1389011,"avatar_url":"https://avatars.githubusercontent.com/u/1389011?v=3","gravatar_id":"","url":"https://api.github.com/users/mrackwitz","html_url":"https://github.com/mrackwitz","followers_url":"https://api.github.com/users/mrackwitz/followers","following_url":"https://api.github.com/users/mrackwitz/following{/other_user}","gists_url":"https://api.github.com/users/mrackwitz/gists{/gist_id}","starred_url":"https://api.github.com/users/mrackwitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrackwitz/subscriptions","organizations_url":"https://api.github.com/users/mrackwitz/orgs","repos_url":"https://api.github.com/users/mrackwitz/repos","events_url":"https://api.github.com/users/mrackwitz/events{/privacy}","received_events_url":"https://api.github.com/users/mrackwitz/received_events","type":"User","site_admin":false},"created_at":"2015-08-31T08:23:14Z","updated_at":"2015-08-31T08:23:14Z","body":">I think you added Error.swift to the Realm/ directory instead of just in RealmSwift-swift2.0/. Also, this would be the first time there's a file just for swift 2 and not 1.2, but the same Xcode project is used for both, so if we go with this, we'll need a stub Error.swift file for Swift 1.2 so Xcode can find it.\r\n\r\nThanks for pointing out, didn't quite catched all those implications.\r\n\r\n>Why is Realm.Error is a struct with mutually exclusive static functions rather than an enum?\r\n\r\nThe solution is inspired by `NSCocoaError`. I don't see any advantage by using an enum. It would be nice, if we could use the defined `RLMError` codes as raw values, but Swift allows only literals.\r\n\r\n>Also, I don't think it's necessary to nest the Error type under Realm. Having it at the top-level would be preferable.\r\n\r\nI agree. I came up with the idea in a different namescape. :wink:"}}