Skip to content

Commit c709d54

Browse files
author
Rachel Prince
committed
Improved error messages with error resolution guidance.
1 parent 0373838 commit c709d54

13 files changed

+80
-106
lines changed

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/AabUpdater.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import androidx.annotation.GuardedBy;
2626
import androidx.annotation.NonNull;
2727
import androidx.annotation.VisibleForTesting;
28-
import com.google.firebase.appdistribution.Constants.ErrorMessages;
28+
2929
import com.google.firebase.appdistribution.internal.InstallActivity;
3030
import com.google.firebase.appdistribution.internal.LogWrapper;
3131
import com.google.firebase.appdistribution.internal.SignInResultActivity;
@@ -181,7 +181,7 @@ void tryCancelAabUpdateTask() {
181181
safeSetTaskException(
182182
cachedUpdateTask,
183183
new FirebaseAppDistributionException(
184-
ErrorMessages.UPDATE_CANCELED,
184+
FirebaseAppDistributionException.ErrorMessages.UPDATE_CANCELED,
185185
FirebaseAppDistributionException.Status.INSTALLATION_CANCELED,
186186
ReleaseUtils.convertToAppDistributionRelease(aabReleaseInProgress)));
187187
}

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/ApkInstaller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void trySetInstallTaskError() {
8787
safeSetTaskException(
8888
installTaskCompletionSource,
8989
new FirebaseAppDistributionException(
90-
Constants.ErrorMessages.APK_INSTALLATION_FAILED,
90+
FirebaseAppDistributionException.ErrorMessages.APK_INSTALLATION_FAILED,
9191
FirebaseAppDistributionException.Status.INSTALLATION_FAILURE));
9292
}
9393
}

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/ApkUpdater.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.google.android.gms.tasks.Task;
2929
import com.google.android.gms.tasks.TaskCompletionSource;
3030
import com.google.firebase.FirebaseApp;
31-
import com.google.firebase.appdistribution.Constants.ErrorMessages;
3231
import com.google.firebase.appdistribution.FirebaseAppDistributionException.Status;
3332
import com.google.firebase.appdistribution.internal.LogWrapper;
3433
import java.io.BufferedOutputStream;
@@ -131,7 +130,7 @@ private void installApk(File file, boolean showDownloadNotificationManager) {
131130
UpdateStatus.INSTALL_FAILED,
132131
showDownloadNotificationManager);
133132
setUpdateTaskCompletionErrorWithDefault(
134-
e, ErrorMessages.APK_INSTALLATION_FAILED, Status.INSTALLATION_FAILURE);
133+
e, FirebaseAppDistributionException.ErrorMessages.APK_INSTALLATION_FAILED, Status.INSTALLATION_FAILURE);
135134
});
136135
}
137136

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/Constants.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/FirebaseAppDistribution.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.google.android.gms.tasks.TaskCompletionSource;
3333
import com.google.android.gms.tasks.Tasks;
3434
import com.google.firebase.FirebaseApp;
35-
import com.google.firebase.appdistribution.Constants.ErrorMessages;
3635
import com.google.firebase.appdistribution.FirebaseAppDistributionException.Status;
3736
import com.google.firebase.appdistribution.internal.LogWrapper;
3837
import com.google.firebase.appdistribution.internal.SignInStorage;
@@ -233,13 +232,13 @@ private Task<Void> showSignInConfirmationDialog(Activity hostActivity) {
233232
(dialogInterface, i) ->
234233
showSignInDialogTask.setException(
235234
new FirebaseAppDistributionException(
236-
ErrorMessages.AUTHENTICATION_CANCELED, AUTHENTICATION_CANCELED)));
235+
FirebaseAppDistributionException.ErrorMessages.AUTHENTICATION_CANCELED, AUTHENTICATION_CANCELED)));
237236

238237
signInConfirmationDialog.setOnCancelListener(
239238
dialogInterface ->
240239
showSignInDialogTask.setException(
241240
new FirebaseAppDistributionException(
242-
ErrorMessages.AUTHENTICATION_CANCELED, AUTHENTICATION_CANCELED)));
241+
FirebaseAppDistributionException.ErrorMessages.AUTHENTICATION_CANCELED, AUTHENTICATION_CANCELED)));
243242

244243
signInConfirmationDialog.show();
245244

@@ -323,13 +322,13 @@ private UpdateTask updateApp(boolean showDownloadInNotificationManager) {
323322
LogWrapper.getInstance().v("New release not found.");
324323
return getErrorUpdateTask(
325324
new FirebaseAppDistributionException(
326-
Constants.ErrorMessages.NOT_FOUND_ERROR, UPDATE_NOT_AVAILABLE));
325+
FirebaseAppDistributionException.ErrorMessages.NOT_FOUND_ERROR, UPDATE_NOT_AVAILABLE));
327326
}
328327
if (cachedNewRelease.getDownloadUrl() == null) {
329328
LogWrapper.getInstance().v("Download failed to execute.");
330329
return getErrorUpdateTask(
331330
new FirebaseAppDistributionException(
332-
Constants.ErrorMessages.DOWNLOAD_URL_NOT_FOUND,
331+
FirebaseAppDistributionException.ErrorMessages.DOWNLOAD_URL_NOT_FOUND,
333332
FirebaseAppDistributionException.Status.DOWNLOAD_FAILURE));
334333
}
335334

@@ -358,7 +357,7 @@ void onActivityResumed(Activity activity) {
358357
if (dialogHostActivity != null && dialogHostActivity != activity) {
359358
showSignInDialogTask.setException(
360359
new FirebaseAppDistributionException(
361-
ErrorMessages.HOST_ACTIVITY_INTERRUPTED, HOST_ACTIVITY_INTERRUPTED));
360+
FirebaseAppDistributionException.ErrorMessages.HOST_ACTIVITY_INTERRUPTED, HOST_ACTIVITY_INTERRUPTED));
362361
} else {
363362
showSignInConfirmationDialog(activity);
364363
}
@@ -368,7 +367,7 @@ void onActivityResumed(Activity activity) {
368367
if (dialogHostActivity != null && dialogHostActivity != activity) {
369368
showUpdateDialogTask.setException(
370369
new FirebaseAppDistributionException(
371-
ErrorMessages.HOST_ACTIVITY_INTERRUPTED, HOST_ACTIVITY_INTERRUPTED));
370+
FirebaseAppDistributionException.ErrorMessages.HOST_ACTIVITY_INTERRUPTED, HOST_ACTIVITY_INTERRUPTED));
372371
} else {
373372
synchronized (cachedNewReleaseLock) {
374373
showUpdateConfirmationDialog(
@@ -447,13 +446,13 @@ private Task<Void> showUpdateConfirmationDialog(
447446
(dialogInterface, i) ->
448447
showUpdateDialogTask.setException(
449448
new FirebaseAppDistributionException(
450-
ErrorMessages.UPDATE_CANCELED, Status.INSTALLATION_CANCELED)));
449+
FirebaseAppDistributionException.ErrorMessages.UPDATE_CANCELED, Status.INSTALLATION_CANCELED)));
451450

452451
updateConfirmationDialog.setOnCancelListener(
453452
dialogInterface ->
454453
showUpdateDialogTask.setException(
455454
new FirebaseAppDistributionException(
456-
ErrorMessages.UPDATE_CANCELED, Status.INSTALLATION_CANCELED)));
455+
FirebaseAppDistributionException.ErrorMessages.UPDATE_CANCELED, Status.INSTALLATION_CANCELED)));
457456

458457
updateConfirmationDialog.show();
459458

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/FirebaseAppDistributionException.java

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,40 @@
1717
import androidx.annotation.NonNull;
1818
import androidx.annotation.Nullable;
1919
import com.google.firebase.FirebaseException;
20-
import com.google.firebase.appdistribution.Constants.ErrorMessages;
2120

2221
/** The class for all Exceptions thrown by {@link FirebaseAppDistribution}. */
2322
public class FirebaseAppDistributionException extends FirebaseException {
2423
/** Enum for potential error statuses that caused the {@link FirebaseAppDistributionException}. */
2524
public enum Status {
26-
/** Unknown error. */
25+
/** Unknown error or an error from a different error domain. */
2726
UNKNOWN,
2827

29-
/** The authentication process failed. */
28+
/** The authentication process failed. The tester was either not signed in, or something went wrong. Try signing in again by calling {@link FirebaseAppDistribution#signInTester}. */
3029
AUTHENTICATION_FAILURE,
3130

32-
/** The authentication process was canceled. */
31+
/** The authentication process was canceled (typically by the user). */
3332
AUTHENTICATION_CANCELED,
3433

35-
/** No network is available to make requests, or the request timed out. */
34+
/** No network is available to make requests, or the request timed out. Check your internet connection and try again. */
3635
NETWORK_FAILURE,
3736

38-
/** The new release failed to download. */
37+
/** The new release failed to download. This is a most likely due to a transient condition and
38+
* may be corrected by retrying. */
3939
DOWNLOAD_FAILURE,
4040

41-
/** The new release failed to install. */
41+
/** The new release failed to install. Verify that the new release has the same signing key as the version running on device. */
4242
INSTALLATION_FAILURE,
4343

44-
/** The installation was canceled. */
44+
/** The installation was canceled (typically by the user). */
4545
INSTALLATION_CANCELED,
4646

47-
/** An update is not available for the current tester and app. */
47+
/** An update is not available for the current tester and app. Make sure that {@link FirebaseAppDistribution#checkForNewRelease()} returns with a non-null {@link AppDistributionRelease} before calling {@link FirebaseAppDistribution#updateApp()} */
4848
UPDATE_NOT_AVAILABLE,
4949

50-
/** The app is running in production. */
50+
/** The app is running in production. The App Distribution SDK is intended for beta testing usage only. Do not include the App Distribution SDK in production builds. */
5151
APP_RUNNING_IN_PRODUCTION,
5252

53-
/** The host activity for a confirmation dialog was destroyed or pushed to the backstack. */
53+
/** The host activity for a confirmation dialog was destroyed or pushed to the backstack. Try calling {@link FirebaseAppDistribution#updateIfNewReleaseAvailable()} again */
5454
HOST_ACTIVITY_INTERRUPTED,
5555
}
5656

@@ -107,4 +107,33 @@ static FirebaseAppDistributionException wrap(Throwable t) {
107107
return new FirebaseAppDistributionException(
108108
String.format("%s: %s", ErrorMessages.UNKNOWN_ERROR, t.getMessage()), Status.UNKNOWN, t);
109109
}
110+
111+
static class ErrorMessages {
112+
public static final String NETWORK_ERROR =
113+
"Failed to fetch releases due to unknown network error.";
114+
115+
public static final String JSON_PARSING_ERROR = "Error parsing service response.";
116+
117+
public static final String AUTHENTICATION_ERROR = "Failed to authenticate the tester.";
118+
119+
public static final String AUTHORIZATION_ERROR = "Failed to authorize the tester.";
120+
121+
public static final String AUTHENTICATION_CANCELED = "Tester canceled the authentication flow.";
122+
123+
public static final String NOT_FOUND_ERROR = "Tester or release not found.";
124+
125+
public static final String TIMEOUT_ERROR = "Failed to fetch releases due to timeout.";
126+
127+
public static final String UPDATE_CANCELED = "Update canceled.";
128+
129+
public static final String UNKNOWN_ERROR = "Unknown error.";
130+
131+
public static final String DOWNLOAD_URL_NOT_FOUND = "Download URL not found.";
132+
133+
public static final String HOST_ACTIVITY_INTERRUPTED =
134+
"Host activity interrupted while dialog was showing.";
135+
136+
public static final String APK_INSTALLATION_FAILED =
137+
"The APK failed to install or installation was canceled.";
138+
}
110139
}

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/FirebaseAppDistributionTesterApiClient.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import androidx.annotation.VisibleForTesting;
2222
import com.google.android.gms.common.util.AndroidUtilsLight;
2323
import com.google.android.gms.common.util.Hex;
24-
import com.google.firebase.appdistribution.Constants.ErrorMessages;
2524
import com.google.firebase.appdistribution.FirebaseAppDistributionException.Status;
2625
import com.google.firebase.appdistribution.internal.LogWrapper;
2726
import java.io.BufferedInputStream;
@@ -89,7 +88,7 @@ AppDistributionReleaseInternal fetchNewRelease(
8988
responseBody = readResponseBody(connection);
9089
} catch (IOException e) {
9190
throw new FirebaseAppDistributionException(
92-
ErrorMessages.NETWORK_ERROR, Status.NETWORK_FAILURE, e);
91+
FirebaseAppDistributionException.ErrorMessages.NETWORK_ERROR, Status.NETWORK_FAILURE, e);
9392
} finally {
9493
if (connection != null) {
9594
connection.disconnect();
@@ -162,7 +161,7 @@ private AppDistributionReleaseInternal parseNewRelease(String responseBody)
162161
} catch (JSONException e) {
163162
LogWrapper.getInstance().e(TAG + "Error parsing the new release.", e);
164163
throw new FirebaseAppDistributionException(
165-
ErrorMessages.JSON_PARSING_ERROR, Status.UNKNOWN, e);
164+
FirebaseAppDistributionException.ErrorMessages.JSON_PARSING_ERROR, Status.UNKNOWN, e);
166165
}
167166
}
168167

@@ -173,17 +172,17 @@ private FirebaseAppDistributionException getExceptionForHttpResponse(int respons
173172
"Bad request when fetching new release", Status.UNKNOWN);
174173
case 401:
175174
return new FirebaseAppDistributionException(
176-
ErrorMessages.AUTHENTICATION_ERROR, Status.AUTHENTICATION_FAILURE);
175+
FirebaseAppDistributionException.ErrorMessages.AUTHENTICATION_ERROR, Status.AUTHENTICATION_FAILURE);
177176
case 403:
178177
return new FirebaseAppDistributionException(
179-
ErrorMessages.AUTHORIZATION_ERROR, Status.AUTHENTICATION_FAILURE);
178+
FirebaseAppDistributionException.ErrorMessages.AUTHORIZATION_ERROR, Status.AUTHENTICATION_FAILURE);
180179
case 404:
181180
return new FirebaseAppDistributionException(
182181
"App or tester not found when fetching new release", Status.AUTHENTICATION_FAILURE);
183182
case 408:
184183
case 504:
185184
return new FirebaseAppDistributionException(
186-
ErrorMessages.TIMEOUT_ERROR, Status.NETWORK_FAILURE);
185+
FirebaseAppDistributionException.ErrorMessages.TIMEOUT_ERROR, Status.NETWORK_FAILURE);
187186
default:
188187
return new FirebaseAppDistributionException(
189188
"Received error status when fetching new release: " + responseCode, Status.UNKNOWN);

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/TesterSignInManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.google.android.gms.tasks.TaskCompletionSource;
3333
import com.google.android.gms.tasks.Tasks;
3434
import com.google.firebase.FirebaseApp;
35-
import com.google.firebase.appdistribution.Constants.ErrorMessages;
3635
import com.google.firebase.appdistribution.FirebaseAppDistributionException.Status;
3736
import com.google.firebase.appdistribution.internal.InstallActivity;
3837
import com.google.firebase.appdistribution.internal.LogWrapper;
@@ -111,7 +110,7 @@ void onActivityStarted(Activity activity) {
111110
LogWrapper.getInstance().e("App Resumed without sign in flow completing.");
112111
setSignInTaskCompletionError(
113112
new FirebaseAppDistributionException(
114-
Constants.ErrorMessages.AUTHENTICATION_CANCELED, AUTHENTICATION_CANCELED));
113+
FirebaseAppDistributionException.ErrorMessages.AUTHENTICATION_CANCELED, AUTHENTICATION_CANCELED));
115114
}
116115
}
117116
}
@@ -139,10 +138,10 @@ public Task<Void> signInTester() {
139138
.get()
140139
.getId()
141140
.addOnFailureListener(
142-
handleTaskFailure(ErrorMessages.AUTHENTICATION_ERROR, Status.AUTHENTICATION_FAILURE))
141+
handleTaskFailure(FirebaseAppDistributionException.ErrorMessages.AUTHENTICATION_ERROR, Status.AUTHENTICATION_FAILURE))
143142
.onSuccessTask(this::getForegroundActivityAndOpenSignInFlow)
144143
// Catch any unexpected failures to be safe.
145-
.addOnFailureListener(handleTaskFailure(ErrorMessages.UNKNOWN_ERROR, Status.UNKNOWN));
144+
.addOnFailureListener(handleTaskFailure(FirebaseAppDistributionException.ErrorMessages.UNKNOWN_ERROR, Status.UNKNOWN));
146145

147146
return signInTaskCompletionSource.getTask();
148147
}

firebase-appdistribution/src/test/java/com/google/firebase/appdistribution/AabUpdaterTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import android.app.Activity;
2727
import android.net.Uri;
2828
import com.google.firebase.FirebaseApp;
29-
import com.google.firebase.appdistribution.Constants.ErrorMessages;
3029
import com.google.firebase.appdistribution.FirebaseAppDistributionException.Status;
3130
import java.io.ByteArrayInputStream;
3231
import java.io.IOException;
@@ -166,7 +165,7 @@ public void updateAppTask_onAppResume_setsUpdateCancelled() throws InterruptedEx
166165
aabUpdater.onActivityStarted(activity);
167166

168167
FirebaseAppDistributionException exception =
169-
assertTaskFailure(updateTask, Status.INSTALLATION_CANCELED, ErrorMessages.UPDATE_CANCELED);
168+
assertTaskFailure(updateTask, Status.INSTALLATION_CANCELED, FirebaseAppDistributionException.ErrorMessages.UPDATE_CANCELED);
170169
assertEquals(
171170
ReleaseUtils.convertToAppDistributionRelease(TEST_RELEASE_NEWER_AAB_INTERNAL),
172171
exception.getRelease());

firebase-appdistribution/src/test/java/com/google/firebase/appdistribution/ApkUpdaterTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.google.android.gms.tasks.Tasks;
3131
import com.google.firebase.FirebaseApp;
3232
import com.google.firebase.FirebaseOptions;
33-
import com.google.firebase.appdistribution.Constants.ErrorMessages;
3433
import com.google.firebase.appdistribution.FirebaseAppDistributionException.Status;
3534
import java.io.File;
3635
import java.io.IOException;
@@ -187,7 +186,7 @@ public void updateApk_whenInstallFailed_setsError() {
187186

188187
installTaskCompletionSource.setException(
189188
new FirebaseAppDistributionException(
190-
Constants.ErrorMessages.APK_INSTALLATION_FAILED,
189+
FirebaseAppDistributionException.ErrorMessages.APK_INSTALLATION_FAILED,
191190
FirebaseAppDistributionException.Status.INSTALLATION_FAILURE));
192191

193192
assertThat(updateTask.isComplete()).isFalse();
@@ -214,7 +213,7 @@ public void updateApk_showNotificationFalse_doesNotUpdateNotificationManager() {
214213

215214
installTaskCompletionSource.setException(
216215
new FirebaseAppDistributionException(
217-
ErrorMessages.APK_INSTALLATION_FAILED, Status.INSTALLATION_FAILURE));
216+
FirebaseAppDistributionException.ErrorMessages.APK_INSTALLATION_FAILED, Status.INSTALLATION_FAILURE));
218217

219218
FirebaseAppDistributionException e =
220219
assertThrows(FirebaseAppDistributionException.class, () -> onCompleteListener.await());

0 commit comments

Comments
 (0)