Description
Related issues
[REQUIRED] Version info
node: 10.22.0
firebase-functions: 3.11.0
firebase-tools: 8.9.0
firebase-admin: 8.13.0
[REQUIRED] Test case
const firebaseFunctions = require('firebase-functions');
try {
throw new Error('Message from the thrown error.');
} catch (err) {
firebaseFunctions.logger.error('Logged message', err);
}
[REQUIRED] Steps to reproduce
Run the test case. For example:
const firebaseFunctions = require('firebase-functions');
it('Test', () => {
try {
throw new Error('Message from the thrown error.');
} catch (err) {
firebaseFunctions.logger.error('Logged message', err);
}
});
[REQUIRED] Expected behavior
Something like:
{
"severity":"ERROR",
"message":"Logged message"
"stack":"Error: Message from the thrown error.\n <insert stack>"
}
[REQUIRED] Actual behavior
{
"severity":"ERROR",
"message":"Logged message Error: Message from the thrown error.\n <insert stack>"
}
Were you able to successfully deploy your functions?
Yes, it deploys fine. This is about logging errors in a way that is easier to read.
The actual output isn't ideal because the the logged message
("Logged message ") is concatenated with the Error
object's message
("Message from the thrown error.") and stack
. It's clear this happens because Error isn't a simple object, which means the logger won't interpret it as a "jsonPayload". However, this makes reading errors more difficult. Is there a way to log errors so that the output is more like the following?
This is just the tip of the iceberg, because I'd like to create custom error class
es that extends
the Error
class, but those print just as poorly.