'Firebase Functions Finished with status: error
I am writing my first Firebase Function that is supposed to make a collection with a document inside (in Firestore) when a new user registers. The only logs I am getting are the following:
Function execution started
and
Function execution took 194 ms. Finished with status: error.
The versions of the dependencies:
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.20.0"
This is my code:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();
exports.newUser = functions.auth.user().onCreate((user) => {
return db
.collection("users")
.doc(user.uid)
.create(JSON.parse(JSON.stringify(user)));
});
When I tried outputting the user.uid in the logs with
return functions.logger.log(user.uid);
I got the expected results as it output the uid as requested, meaning that the problem isn't with getting the user.
I have read this question, but it didn't solve my problem. Any ideas?
Solution 1:[1]
I have faced the same error because I was using the command : "firebase deploy " to deploy the function but when I used the command : "firebase deploy --only functions " the function gets deployed successfully.
Solution 2:[2]
What you want is the remainder, multiplied by 10 until the remainder is 0. Using BigDecimal to prevent rounding issues that looks like this:
final BigDecimal input = new BigDecimal("5.456");
BigDecimal x = input.remainder(BigDecimal.ONE);
while (x.remainder(BigDecimal.ONE).compareTo(BigDecimal.ZERO) > 0) {
x = x.multiply(new BigDecimal(10));
}
System.out.println(x.longValue());
Solution 3:[3]
Here are two ways that don't adjust for floating point anomalies.
double s = 5.456;
System.out.println(s%1);
or
System.out.println(s-(int)s);
both print
0.4560000000000004
Or use BigDecimal and adjust the scale and subtract the integer value.
System.out.println(BigDecimal.valueOf(s)
.setScale(3)
.subtract(BigDecimal.valueOf((int)s)));
prints
.456
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Abhishek Chauhan |
| Solution 2 | Karsten Gabriel |
| Solution 3 |
