Skip to content

Commit 885637e

Browse files
M0rtyMerrfreak4pc
authored andcommitted
Add Hooks documentation, remove unexpected logs (ReactiveX#1988)
1 parent c83b9cb commit 885637e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Documentation/GettingStarted.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,19 @@ You can recover from failure of observable by using `catch` operator. There are
727727

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

730+
### Hooks and Default error handling
731+
732+
RxSwift offers a global Hook that provides a default error handling mechanism for cases when you don't provide your own `onError` handler.
733+
734+
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.
735+
736+
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.
737+
738+
In order to enable detailed callstack logging, set `Hooks.recordCallStackOnError` flag to `true`.
739+
740+
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.
741+
742+
730743
## Debugging Compile Errors
731744

732745
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.

RxSwift/ObservableType+Extensions.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ extension Hooks {
9393
fileprivate static var _defaultErrorHandler: DefaultErrorHandler = { subscriptionCallStack, error in
9494
#if DEBUG
9595
let serializedCallStack = subscriptionCallStack.joined(separator: "\n")
96-
print("Unhandled error happened: \(error)\n subscription called from:\n\(serializedCallStack)")
96+
print("Unhandled error happened: \(error)")
97+
if !serializedCallStack.isEmpty {
98+
print("subscription called from:\n\(serializedCallStack)")
99+
}
97100
#endif
98101
}
99102
fileprivate static var _customCaptureSubscriptionCallstack: CustomCaptureSubscriptionCallstack = {

0 commit comments

Comments
 (0)