Skip to content

Using the transport with wrong credentials causes crash when logging #870

@RLRabinowitz

Description

@RLRabinowitz

Please make sure you have searched for information in the following guides.

A screenshot that you have tested with "Try this API".

Not a problem with the API, a problem with the library

Link to the code that reproduces this issue. A link to a public Github Repository or gist with a minimal reproduction.

https://gist.github.com/RLRabinowitz/d37492e3627e73c14e1cbe16ba1162a9

A step-by-step description of how to reproduce the issue, based on the linked reproduction.

Have the following code:


// NOTE - These should be valid credentials, but should miss the `client_email` field:
const credentials = {...}

const transport = new LoggingWinston({ 
  logName: "my-log-name",
  projectId: "my-project-id",
  credentials,
  defaultCallback: (error, apiResponse) => {
    if (error) {
      logger.error('GCP Transport got error', { error, apiResponse: JSON.stringify(apiResponse) });
    }
  }
})

const loggerOptions = {
  levels: winston.config.syslog.levels,
  level: 'debug',
  transports: [transport],
  exitOnError: false
}

const logger = winston.createLogger(loggerOptions);

// Try to log
logger.info('test')

// Wait 3 seconds
await new Promise(resolve => setTimeout(resolve, 3000));

A clear and concise description of what the bug is, and what you expected to happen.

You get the following crash, as an Unhandled Exception:

Error: The incoming JSON object does not contain a client_email field

    at JWT.fromJSON (/Users/arelrabinowitz/Projects/myproject/node_modules/.pnpm/[email protected][email protected]/node_modules/google-auth-library/build/src/auth/jwtclient.js:203:19)
    at GoogleAuth.fromJSON (/Users/arelrabinowitz/Projects/myproject/node_modules/.pnpm/[email protected][email protected]/node_modules/google-auth-library/build/src/auth/googleauth.js:435:20)
    at GoogleAuth._cacheClientFromJSON (/Users/arelrabinowitz/Projects/myproject/node_modules/.pnpm/[email protected][email protected]/node_modules/google-auth-library/build/src/auth/googleauth.js:447:29)
    at GoogleAuth.getClient (/Users/arelrabinowitz/Projects/myproject/node_modules/.pnpm/[email protected][email protected]/node_modules/google-auth-library/build/src/auth/googleauth.js:665:22)
    at GrpcClient._getCredentials (/Users/arelrabinowitz/Projects/myproject/node_modules/.pnpm/[email protected][email protected]/node_modules/google-gax/build/src/grpc.js:145:40)
    at GrpcClient.createStub (/Users/arelrabinowitz/Projects/myproject/node_modules/.pnpm/[email protected][email protected]/node_modules/google-gax/build/src/grpc.js:308:34)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)

Adding a try/catch over the logger.info would not help, and the defaultCallback didn't help here either

A clear and concise description WHY you expect this behavior, i.e., was it a recent change, there is documentation that points to this behavior, etc. **

Logging with winston should not crash

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/nodejs-logging-winston API.priority: p3Desirable enhancement or fix. May not be included in next release.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions