Skip to content

functions.logger.error includes stack trace in message containing entryFromArgs #1337

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

Closed
cdiddy77 opened this issue Jan 14, 2023 · 2 comments
Assignees

Comments

@cdiddy77
Copy link

Related issues

None

[REQUIRED] Version info

node:16

firebase-functions:4.1.1

firebase-tools:10.6.0-11.20.0

firebase-admin:11.4.1

[REQUIRED] Test case

import * as functions from "firebase-functions";

export const someFunction = functions.https.onCall(
  async (
    data: unknown
  ): Promise<{}> => {
     functions.logger.error("some message", { });
     return {};
  }
);

[REQUIRED] Steps to reproduce

deploy and run the above function

[REQUIRED] Expected behavior

print error like before #1161

 {"severity":"ERROR","message":"some message", payload: {} }

[REQUIRED] Actual behavior

prints wacky stack filled error:

 {"severity":"ERROR","message":"Error: some message\n    at entryFromArgs (C:\\Users\\charl\\dev\\getfilta\\nplus1\\packages\\functions\\node_modules\\firebase-functions\\lib\\logger\\index.js:130:19)\n    at Object.error (C:\\Users\\charl\\dev\\getfilta\\nplus1\\packages\\functions\\node_modules\\firebase-functions\\lib\\logger\\index.js:116:11)\n    at <MY CODE ON STACK>   at newHandler (C:\\Users\\charl\\dev\\getfilta\\nplus1\\packages\\functions\\node_modules\\firebase-tools\\lib\\emulator\\functionsEmulatorRuntime.js:319:16)\n    at fixedLen (C:\\Users\\charl\\dev\\getfilta\\nplus1\\packages\\functions\\node_modules\\firebase-functions\\lib\\v1\\providers\\https.js:74:41)\n    at C:\\Users\\charl\\dev\\getfilta\\nplus1\\packages\\functions\\node_modules\\firebase-functions\\lib\\common\\providers\\https.js:411:32\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async runFunction (C:\\Users\\charl\\dev\\getfilta\\nplus1\\packages\\functions\\node_modules\\firebase-tools\\lib\\emulator\\functionsEmulatorRuntime.js:564:9)\n    at async runHTTPS (C:\\Users\\charl\\dev\\getfilta\\nplus1\\packages\\functions\\node_modules\\firebase-tools\\lib\\emulator\\functionsEmulatorRuntime.js:590:5)\n    at async handler (C:\\Users\\charl\\dev\\getfilta\\nplus1\\packages\\functions\\node_modules\\firebase-tools\\lib\\emulator\\functionsEmulatorRuntime.js:510:17)"}

Were you able to successfully deploy your functions?

yes

The commit based on #1161 introduced a change to entryFromArgs which mucks with the message, introducing an entire callstack. The comment leads the reader to believe this is to emulate some sort of behavior of console.log, but this seems very questionable.

@Schmale97
Copy link

This behaviour seems odd because when it doesn't seem to match console.error - which isn't adding a stack trace
Output from console.error:
Validation error: Required at "foo"

Output from firebase.logger.error:
{"severity":"ERROR","message":"Error: Validation error: Required at "foo"\n at entryFromArgs (/Users/user/project/functions/node_modules/firebase-functions/lib/logger/index.js:130:19)\n at Object.error (/Users/user/project/functions/node_modules/firebase-functions/lib/logger/index.js:116:11)\n at _ColleagueV1Repository.fetchColleague (file:///Users/user/project/functions/lib/index.js:388:19)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async file:///Users/user/project/functions/lib/index.js:488:21\n at async /Users/user/project/functions/node_modules/firebase-functions/lib/common/providers/https.js:438:26\n at async runFunction (/Users/user/.nvm/versions/node/v18.15.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:506:9)\n at async runHTTPS (/Users/user/.nvm/versions/node/v18.15.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:531:5)\n at async /Users/user/.nvm/versions/node/v18.15.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:690:21"}

@colerogers colerogers self-assigned this Apr 28, 2023
@colerogers
Copy link
Contributor

Hey folks, so this is actually working as intended. If you want to take a peek at the original PR that has a thorough description here it is. Basically, we need to always send the stack trace for Cloud Run to correctly send the error to Cloud Error Reporting. Sorry about the confusion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants