arrow-kt / arrow-core

Λrrow Core is part of Λrrow, a functional companion to Kotlin's Standard Library
http://arrow-kt.io
Other
81 stars 30 forks source link

Don't match cancellation in NonFatal #308

Closed nomisRev closed 3 years ago

nomisRev commented 3 years ago

In Kotlin 1.4 CancellationException was added as a cancellation system for coroutines. We thus shouldn't match CancellationException in NonFatal, or it would be prone to being swallowed in user code.

I.e. if fetchUser is cancelled it throws CancellationException, and in the below snippet it could be easily swalled and mapped to a default error type. This would easily cause bugs, and we should let CancellationException propagate through the program so it can cancel any outer scopes.

val user = Either.catch {
  fetchUser()
}.mapLeft { DomainError.UnkownError(it) }