Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Copy Markdown
Contributor

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)
)

Copy link
Copy Markdown
Contributor Author

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.

Log.e("BaseCredentialsManager", "Unexpected error in executor block", t)
callback.onFailure(
CredentialsManagerException(CredentialsManagerException.Code.UNKNOWN_ERROR, t)
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add log
line here? Something like:

} catch (t: Throwable) {
Log.e("BaseCredentialsManager", "Unexpected error in executor block", t)
callback.onFailure(...)
}
will be helpful if a customer reports a weird failure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Added log to record the error

}
}
}
Loading
Loading