-
Notifications
You must be signed in to change notification settings - Fork 170
fix : Guard against all uncaught exception in the serial executor block #970
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -313,6 +313,19 @@ public abstract class BaseCredentialsManager internal constructor( | |
| if (scope == null) return audience | ||
| val sortedScope = scope.split(" ").sorted().joinToString("::") | ||
| return "$audience::${sortedScope}" | ||
| } | ||
|
|
||
| internal inline fun <T> runCatchingOnExecutor( | ||
| callback: Callback<T, CredentialsManagerException>, | ||
| block: () -> Unit | ||
| ) { | ||
| try { | ||
| block() | ||
| } catch (t: Throwable) { | ||
| Log.e("BaseCredentialsManager", "Unexpected error in executor block", t) | ||
| callback.onFailure( | ||
| CredentialsManagerException(CredentialsManagerException.Code.UNKNOWN_ERROR, t) | ||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add log } catch (t: Throwable) {
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Added log to record the error |
||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
atching Throwable here means we'd also swallow OutOfMemoryError, StackOverflowError, etc. — situations where the JVM is in a bad state and the app really should crash. The old code only caught RuntimeException. Could we narrow this to Exception instead? Or re-throw Error subtypes so fatal problems don't get silently eaten:
} catch (e: Exception) {
callback.onFailure(
CredentialsManagerException(CredentialsManagerException.Code.UNKNOWN_ERROR, e)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point on catching too broadly. However, I'm intentionally keeping Throwable here — this is an SDK running on a background executor, and the entire purpose of this fix (#968) is to prevent unhandled exceptions from silently killing the host app. The rationale is that a library should never be the reason an app force-closes without explanation — the host app should own its crash policy.