Skip to content

Commit

Permalink
Add Hooks documentation, remove unexpected logs
Browse files Browse the repository at this point in the history
  • Loading branch information
M0rtyMerr committed May 28, 2019
1 parent 5cd1536 commit 762e25d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Documentation/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,29 @@ You can recover from failure of observable by using `catch` operator. There are

There is also `retry` operator that enables retries in case of errored sequence.

### Default error handling

If you don't provide `onError` callback default handling will be performed. `Hooks` enum is responsible for it.

It just prints received error in `DEBUG` mode and does nothing in`RELEASE`. However, you can add additional configuration to this behavior.

In order to enable detailed callstack logging set `Hooks.recordCallStackOnError` flag.
```swift
/* add somewhere in
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil)
*/
Hooks.recordCallStackOnError = true
...
Observable.just(error).subscribe(onNext: { // detailed callstack will be printed out
print($0)
})

```

Implement `Hooks.customCaptureSubscriptionCallstack` closure, if you need custom way of grabbing logs.

Implement `Hooks.defaultErrorHandler` if you need custom reaction on unhandled errors (e.g. send stacktrace to analytics).

## Debugging Compile Errors

When writing elegant RxSwift/RxCocoa code, you are probably relying heavily on compiler to deduce types of `Observable`s. This is one of the reasons why Swift is awesome, but it can also be frustrating sometimes.
Expand Down
5 changes: 4 additions & 1 deletion RxSwift/ObservableType+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ extension Hooks {
fileprivate static var _defaultErrorHandler: DefaultErrorHandler = { subscriptionCallStack, error in
#if DEBUG
let serializedCallStack = subscriptionCallStack.joined(separator: "\n")
print("Unhandled error happened: \(error)\n subscription called from:\n\(serializedCallStack)")
print("Unhandled error happened: \(error)")
if !serializedCallStack.isEmpty {
print("subscription called from:\n\(serializedCallStack)")
}
#endif
}
fileprivate static var _customCaptureSubscriptionCallstack: CustomCaptureSubscriptionCallstack = {
Expand Down

0 comments on commit 762e25d

Please sign in to comment.