Skip to content

Commit 97fa4e4

Browse files
Mark aliases onError and errorValue as deprecated
And include more documentation on their use.
1 parent ecf6950 commit 97fa4e4

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

Sources/Promise+Properties.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,20 @@ extension Promise {
1414
}
1515

1616
/**
17-
- Returns: The error with which this promise was rejected; `nil` if this promise is not rejected.
18-
Alternative for the cases where the Swift compiler gets confused over the name of the `error` property
17+
Provides an alias for the `error` property for cases where the Swift
18+
compiler cannot disambiguate from our `error` function.
19+
20+
More than likely use of this alias will never be necessary as it's
21+
the inverse situation where Swift usually becomes confused. But
22+
we provide this anyway just in case.
23+
24+
If you absolutely cannot get Swift to accept `error` then
25+
`errorValue` may be used instead as it returns the same thing.
26+
27+
- Warning: This alias will be unavailable in PromiseKit 4.0.0
28+
- SeeAlso: [https://github.com/mxcl/PromiseKit/issues/347](https://github.com/mxcl/PromiseKit/issues/347)
1929
*/
30+
@available(*, deprecated, renamed="error", message="Temporary alias `errorValue` will eventually be removed and should only be used when the Swift compiler cannot be satisfied with `error`")
2031
public var errorValue: ErrorType? {
2132
return self.error
2233
}

Sources/Promise.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,28 @@ public class Promise<T> {
391391
}
392392

393393
/**
394-
Provides an alias for the `error` function for cases where the Swift compiler gets into trouble inferring the right
395-
types. If `error` does not work, consider using `onError` instead which does the same thing.
394+
Provides an alias for the `error` function for cases where the Swift
395+
compiler cannot disambiguate from our `error` property. If you're
396+
having trouble with `error`, before using this alias, first try
397+
being as explicit as possible with the types e.g.:
398+
399+
}.error { (error:ErrorType) -> Void in
400+
//...
401+
}
402+
403+
Or even using verbose function syntax:
404+
405+
}.error({ (error:ErrorType) -> Void in
406+
//...
407+
})
408+
409+
If you absolutely cannot get Swift to accept `error` then `onError`
410+
may be used instead as it does the same thing.
411+
412+
- Warning: This alias will be unavailable in PromiseKit 4.0.0
413+
- SeeAlso: [https://github.com/mxcl/PromiseKit/issues/347](https://github.com/mxcl/PromiseKit/issues/347)
396414
*/
415+
@available(*, deprecated, renamed="error", message="Temporary alias `onError` will eventually be removed and should only be used when the Swift compiler cannot be satisfied with `error`")
397416
public func onError(policy policy: ErrorPolicy = .AllErrorsExceptCancellation, _ body: (ErrorType) -> Void) {
398417
error(policy: policy, body)
399418
}

Tests/CorePromise/ErrorUnhandler.test.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ class ErrorHandlingTests_Swift: XCTestCase {
116116
}
117117
}
118118

119-
120-
// an alias called `onError` exists for the `error` function
119+
// a temporary alias `onError` exists for the `error` function
121120
func test7() {
122121
twice { promise, ex in
123122
PMKUnhandledErrorHandler = { err in

0 commit comments

Comments
 (0)