Hello I am getting some random crashes usually sometime after the user has moved the app to the back...
m

micbakos

almost 3 years ago
Hello I am getting some random crashes usually sometime after the user has moved the app to the background. The stacktrace reports
kotlin::FormatToSpan(kotlin::std_support::span<char, ...>, char const*, ...) + 10
which is mentioned in this channel before. This is the stacktrace in detail:
Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x7b38 __pthread_kill + 8
1  libsystem_pthread.dylib        0x73bc pthread_kill + 268
2  libsystem_c.dylib              0x20524 abort + 168
3  ios                            0x118b4f8 kotlin::FormatToSpan(kotlin::std_support::span<char, 18446744073709551615ul>, char const*, ...) + 10
4  ios                            0x11b3850 ReportBacktraceToIosCrashLog(ObjHeader*) + 38
5  ios                            0x11b3688 void (anonymous namespace)::$_0::operator()<(anonymous namespace)::terminateWithUnhandledException(ObjHeader*)::$_1>((anonymous namespace)::terminateWithUnhandledException(ObjHeader*)::$_1) + 80
6  ios                            0x11b33d0 (anonymous namespace)::TerminateHandler::queuedHandler() + 10
7  ios                            0x11b3384 (anonymous namespace)::processUnhandledException(ObjHeader*) + 64
8  ios                            0x148d3ac kfun:kotlinx.coroutines#handleCoroutineExceptionImpl(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 13 (CoroutineExceptionHandlerImpl.kt:13)
9  ios                            0x1380520 kfun:kotlinx.coroutines#handleCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 33 (CoroutineExceptionHandler.kt:33)
10 ios                            0x1372c04 kfun:kotlinx.coroutines.StandaloneCoroutine.handleJobException#internal + 196 (Builders.common.kt:196)
11 ios                            0x138e614 kfun:kotlinx.coroutines.JobSupport.finalizeFinishingState#internal + 229 (JobSupport.kt:229)
12 ios                            0x1398794 kfun:kotlinx.coroutines.JobSupport.continueCompleting#internal + 935 (JobSupport.kt:935)
13 ios                            0x139b5c8 kfun:kotlinx.coroutines.JobSupport.ChildCompletion.invoke#internal + 1155 (JobSupport.kt:1155)
14 ios                            0x1390c3c kfun:kotlinx.coroutines.JobSupport.notifyCompletion#internal + 368 (JobSupport.kt:368)
15 ios                            0x138fea4 kfun:kotlinx.coroutines.JobSupport.completeStateFinalization#internal + 323 (JobSupport.kt:323)
16 ios                            0x138e4d4 kfun:kotlinx.coroutines.JobSupport.finalizeFinishingState#internal + 240 (JobSupport.kt:240)
17 ios                            0x1397ac4 kfun:kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath#internal + 906 (JobSupport.kt:906)
18 ios                            0x13974d0 kfun:kotlinx.coroutines.JobSupport.tryMakeCompleting#internal + 863 (JobSupport.kt:863)
19 ios                            0x13970b0 kfun:kotlinx.coroutines.JobSupport#makeCompletingOnce(kotlin.Any?){}kotlin.Any? + 828 (JobSupport.kt:828)
20 ios                            0x136d0e8 kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Result<1:0>){} + 100 (AbstractCoroutine.kt:100)
21 ios                            0x1024a38 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 43 (ContinuationImpl.kt:43)
22 ios                            0x145c138 kfun:kotlinx.coroutines.DispatchedTask#run(){} + 54 (Continuation.kt:54)
23 ios                            0x1496b14 kfun:kotlinx.coroutines.DarwinMainDispatcher.dispatch$lambda$0#internal + 44 (Dispatchers.kt:44)
24 ios                            0x1496e84 kfun:kotlinx.coroutines.DarwinMainDispatcher.$dispatch$lambda$0$FUNCTION_REFERENCE$75.invoke#internal + 43 (Dispatchers.kt:43)
25 ios                            0x1496f68 kfun:kotlinx.coroutines.DarwinMainDispatcher.$dispatch$lambda$0$FUNCTION_REFERENCE$75.$<bridge-UNN>invoke(){}#internal + 43 (Dispatchers.kt:43)
26 ios                            0x1497fec _6f72672e6a6574627261696e732e6b6f746c696e783a6b6f746c696e782d636f726f7574696e65732d636f7265_knbridge13 + 43 (Dispatchers.kt:43)
27 libdispatch.dylib              0x1e6c _dispatch_call_block_and_release + 32
28 libdispatch.dylib              0x3a30 _dispatch_client_callout + 20
29 libdispatch.dylib              0x11f48 _dispatch_main_queue_drain + 928
30 libdispatch.dylib              0x11b98 _dispatch_main_queue_callback_4CF + 44
31 CoreFoundation                 0x51800 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
32 CoreFoundation                 0xb704 __CFRunLoopRun + 2532
33 CoreFoundation                 0x1ebc8 CFRunLoopRunSpecific + 600
34 GraphicsServices               0x1374 GSEventRunModal + 164
35 UIKitCore                      0x514b58 -[UIApplication _run] + 1100
36 UIKitCore                      0x296090 UIApplicationMain + 364
37 SwiftUI                        0x23ff24 closure #1 in KitRendererCommon(_:) + 164
38 SwiftUI                        0x16de08 runApp<A>(_:) + 252
39 SwiftUI                        0x14f0f4 static App.main() + 128
40 ios                            0x437fcc static iOSApp.$main() + 40 (<compiler-generated>:40)
41 ios                            0x438074 main + 12 (iOSApp.swift:12)
42 ???                            0x105285da4 (Missing)
Are there any suggestions on where I can start looking for the reason of the crash?
Hi people have you ever encountered this error ```kotlin.NoWhenBranchMatchedException: null at arr...
i

itbhp

almost 4 years ago
Hi people have you ever encountered this error
kotlin.NoWhenBranchMatchedException: null
	at arrow.core.computations.EitherEffect$DefaultImpls.bind(either.kt:20) ~[arrow-core-jvm-1.0.1.jar:?]
I am using the either monad comprehension block and the bind extension function but maybe I am missing something. I am using arrow version 1.0.1 Basically I have few interface with suspended methods, and one interface exposing a method not suspended (and using jooq in the implementation to handle transactions)
interface Repository {
  suspend fun getBy(userId: UserId): Either<Error, List<DomainObject>>
  suspend fun update(obj: DomainObject) : Either<ErrorResult, Unit>
}
class TransactionMgmt(private val dslContext: DSLContext) {

    fun <T> transaction(
        block: () -> Either<Error, T>
    ): Either<ErrorResult, T> ...
interface Observer {

    suspend fun onExpired(obj: DomainObject): Either<ErrorResult, Unit>
}
class ExpireUseCase(
    private val repository: Repository,
    private val transactionMgmt: TransactionMgmt,
    private val observer: Observer
) : UseCase<Request, Response> {
    override suspend fun execute(request: Request): Either<Error, Response> =
        repository.getBy(request.userId)
            .flatMap { obj ->
                updateAndNotify(obj)
            }

    private suspend fun updateAndNotify(objs: List<DomainObject>): Either<Error, Response> {
        return objs.fold(initial) { acc, obj ->
            transactionMgmt.transaction {
                runBlocking {
                    expire(obj, acc)
                }
            }
        }
    }

    private suspend fun expire(
        obj: DomainObject,
        acc: Either<Error, Response>
    ): Either<Error, Response> = either {
        val expiredObj = obj.copy(status = EXPIRED)
        repository.update(expiredObj).bind()
        observer.onExpired(expiredObj).bind()
        Response(acc.bind().count + 1)
    }

    private val initial: Either<Error, Response> = Response(0).right()
}
Basically I am getting that error in the method
private suspend fun expire(
        obj: DomainObject,
        acc: Either<Error, Response>
    ): Either<Error, Response> = either {
        val expiredObj = obj.copy(status = EXPIRED)
        repository.update(expiredObj).bind()
        observer.onExpired(expiredObj).bind()
        Response(acc.bind().count + 1)
    }
Sorry for the very long post, and maybe I am missing something really stupid but I cannot see it. (this is a similar version of the actual code I am using, I cannot post the original one)