Skip to content

Commit

Permalink
Add Hooks documentation, remove unexpected logs (#1988)
Browse files Browse the repository at this point in the history
  • Loading branch information
M0rtyMerr authored and freak4pc committed Jun 3, 2019
1 parent c83b9cb commit 885637e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Documentation/GettingStarted.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -727,6 +727,19 @@ 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. There is also `retry` operator that enables retries in case of errored sequence.


### Hooks and Default error handling

RxSwift offers a global Hook that provides a default error handling mechanism for cases when you don't provide your own `onError` handler.

Set `Hooks.defaultErrorHandler` with your own closure to decide how to deal with unhandled errors in your system, if you need that option. For example, sending the stacktrace or untracked-error to your analytics system.

By default, `Hooks.defaultErrorHandler` simply prints the received error in `DEBUG` mode, and does nothing in `RELEASE`. However, you can add additional configurations to this behavior.

In order to enable detailed callstack logging, set `Hooks.recordCallStackOnError` flag to `true`.

By default, this will return the current `Thread.callStackSymbols` in `DEBUG` mode, and will track an empty stack trace in `RELEASE`. You may customize this behavior by overriding `Hooks.customCaptureSubscriptionCallstack` with your own implementation.


## Debugging Compile Errors ## 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. 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 Original file line Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ extension Hooks {
fileprivate static var _defaultErrorHandler: DefaultErrorHandler = { subscriptionCallStack, error in fileprivate static var _defaultErrorHandler: DefaultErrorHandler = { subscriptionCallStack, error in
#if DEBUG #if DEBUG
let serializedCallStack = subscriptionCallStack.joined(separator: "\n") 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 #endif
} }
fileprivate static var _customCaptureSubscriptionCallstack: CustomCaptureSubscriptionCallstack = { fileprivate static var _customCaptureSubscriptionCallstack: CustomCaptureSubscriptionCallstack = {
Expand Down

0 comments on commit 885637e

Please sign in to comment.