Skip to content

Propagate exceptions to the caller if Fis getToken call fails with an exception. #2035

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

Merged
merged 3 commits into from
Oct 27, 2020
Merged
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 @@ -305,12 +305,12 @@ private void triggerOnStateReached(PersistedInstallationEntry persistedInstallat
}
}

private void triggerOnException(PersistedInstallationEntry prefs, Exception exception) {
private void triggerOnException(Exception exception) {
synchronized (lock) {
Iterator<StateListener> it = listeners.iterator();
while (it.hasNext()) {
StateListener l = it.next();
boolean doneListening = l.onException(prefs, exception);
boolean doneListening = l.onException(exception);
if (doneListening) {
it.remove();
}
Expand Down Expand Up @@ -366,7 +366,7 @@ private void doNetworkCallIfNecessary(boolean forceRefresh) {
return;
}
} catch (FirebaseInstallationsException e) {
triggerOnException(prefs, e);
triggerOnException(e);
return;
}

Expand All @@ -380,11 +380,11 @@ private void doNetworkCallIfNecessary(boolean forceRefresh) {

// Let the caller know about the result.
if (prefs.isErrored()) {
triggerOnException(prefs, new FirebaseInstallationsException(Status.BAD_CONFIG));
triggerOnException(new FirebaseInstallationsException(Status.BAD_CONFIG));
} else if (prefs.isNotGenerated()) {
// If there is no fid it means the call failed with an auth error. Simulate an
// IOException so that the caller knows to try again.
triggerOnException(prefs, new IOException(AUTH_ERROR_MSG));
triggerOnException(new IOException(AUTH_ERROR_MSG));
} else {
triggerOnStateReached(prefs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,8 @@ public boolean onStateReached(PersistedInstallationEntry persistedInstallationEn
}

@Override
public boolean onException(
PersistedInstallationEntry persistedInstallationEntry, Exception exception) {
if (persistedInstallationEntry.isErrored()
|| persistedInstallationEntry.isNotGenerated()
|| persistedInstallationEntry.isUnregistered()) {
resultTaskCompletionSource.trySetException(exception);
return true;
}
return false;
public boolean onException(Exception exception) {
resultTaskCompletionSource.trySetException(exception);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public boolean onStateReached(PersistedInstallationEntry persistedInstallationEn
}

@Override
public boolean onException(
PersistedInstallationEntry persistedInstallationEntry, Exception exception) {
public boolean onException(Exception exception) {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

why don't we fail the completion source if an exception is triggered in the getId path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getId flow should never trigger to propagate exception because we immediately return an FID (when available or generating a new one) even before trying to register the FID with FIS servers.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ interface StateListener {
* Returns {@code true} if an exception is thrown while registering a Firebase Installation,
* {@code false} otherwise.
*/
boolean onException(PersistedInstallationEntry persistedInstallationEntry, Exception exception);
boolean onException(Exception exception);
}