Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

androidContext() swallows/hides underlying exceptions #1932

Closed
yogurtearl opened this issue Aug 2, 2024 · 1 comment
Closed

androidContext() swallows/hides underlying exceptions #1932

yogurtearl opened this issue Aug 2, 2024 · 1 comment
Labels
Milestone

Comments

@yogurtearl
Copy link

If the get() for a context throws an exception, the cause is discarded.
(same applies for Scope.androidApplication())

The e here is discarded.

See this code:

fun Scope.androidContext(): Context = try {
get()
} catch (e: Exception) {
throw MissingAndroidContextException("Can't resolve Context instance. $ERROR_MSG")
}

Instead it should be something like this:

class MissingAndroidContextException(message: String, cause: kotlin.Throwable?)
     : kotlin.Exception(message, cause)

fun Scope.androidContext(): Context = try {
    get()
} catch (e: Exception) {
    throw MissingAndroidContextException("Can't resolve Context instance. $ERROR_MSG", e)
}
@arnaudgiuliani
Copy link
Member

Thanks

arnaudgiuliani added a commit that referenced this issue Sep 9, 2024
Catch Koin injection error only - Fix #1932
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants