Skip to content

Commit 5ea6635

Browse files
authored
Adding descriptive error messaging for preconditions check. (#1715)
1 parent 4748715 commit 5ea6635

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,21 @@ public Thread newThread(Runnable r) {
9494
}
9595
};
9696

97+
private static final String API_KEY_VALIDATION_MSG =
98+
"Please set a valid API key. A Firebase API key is required to communicate with "
99+
+ "Firebase server APIs: It authenticates your project with Google."
100+
+ "Please refer to https://firebase.google.com/support/privacy/init-options.";
101+
102+
private static final String APP_ID_VALIDATION_MSG =
103+
"Please set your Application ID. A valid Firebase App ID is required to communicate "
104+
+ "with Firebase server APIs: It identifies your application with Firebase."
105+
+ "Please refer to https://firebase.google.com/support/privacy/init-options.";
106+
107+
private static final String PROJECT_ID_VALIDATION_MSG =
108+
"Please set your Project ID. A valid Firebase Project ID is required to communicate "
109+
+ "with Firebase server APIs: It identifies your application with Firebase."
110+
+ "Please refer to https://firebase.google.com/support/privacy/init-options.";
111+
97112
/** package private constructor. */
98113
FirebaseInstallations(
99114
FirebaseApp firebaseApp,
@@ -147,19 +162,12 @@ public Thread newThread(Runnable r) {
147162
* or empty.
148163
*/
149164
private void preConditionChecks() {
150-
Preconditions.checkNotEmpty(getApplicationId());
151-
Preconditions.checkNotEmpty(getProjectIdentifier());
152-
Preconditions.checkNotEmpty(getApiKey());
153-
Preconditions.checkArgument(
154-
Utils.isValidAppIdFormat(getApplicationId()),
155-
"Please set your Application ID. A valid Firebase App ID is required to communicate "
156-
+ "with Firebase server APIs: It identifies your application with Firebase."
157-
+ "Please refer to https://firebase.google.com/support/privacy/init-options.");
165+
Preconditions.checkNotEmpty(getApplicationId(), APP_ID_VALIDATION_MSG);
166+
Preconditions.checkNotEmpty(getProjectIdentifier(), PROJECT_ID_VALIDATION_MSG);
167+
Preconditions.checkNotEmpty(getApiKey(), API_KEY_VALIDATION_MSG);
158168
Preconditions.checkArgument(
159-
Utils.isValidApiKeyFormat(getApiKey()),
160-
"Please set a valid API key. A Firebase API key is required to communicate with "
161-
+ "Firebase server APIs: It authenticates your project with Google."
162-
+ "Please refer to https://firebase.google.com/support/privacy/init-options.");
169+
Utils.isValidAppIdFormat(getApplicationId()), APP_ID_VALIDATION_MSG);
170+
Preconditions.checkArgument(Utils.isValidApiKeyFormat(getApiKey()), API_KEY_VALIDATION_MSG);
163171
}
164172

165173
/** Returns the Project Id or Project Number for the Firebase Project. */

0 commit comments

Comments
 (0)