lazywithclass/winston-cloudwatch

TypeError: callback is not a function

Closed this issue · 8 comments

Hello,

I have this code:

const winston = require('winston');
const winstonCloudwatch = require('winston-cloudwatch');

winston.add(new winstonCloudwatch({
    logGroupName: 'testing',
    logStreamName: 'first'
}));

winston.error('1');

and I receive this error:

/vagrant/convertup/service-mail/node_modules/winston-cloudwatch/index.js:74
    return callback(null, true);
           ^

TypeError: callback is not a function
    at WinstonCloudWatch.log (/vagrant/convertup/service-mail/node_modules/winston-cloudwatch/index.js:74:12)
    at WinstonCloudWatch.TransportStream._write (/vagrant/convertup/service-mail/node_modules/winston-transport/index.js:88:17)
    at doWrite (_stream_writable.js:331:12)
    at writeOrBuffer (_stream_writable.js:317:5)
    at WinstonCloudWatch.Writable.write (_stream_writable.js:243:11)
    at DerivedLogger.ondata (_stream_readable.js:555:20)
    at emitOne (events.js:96:13)
    at DerivedLogger.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at DerivedLogger.Readable.push (_stream_readable.js:134:10)

I am using:

winston: ^3.0.0-rc0,
winston-cloudwatch: ^1.12.0
node: v6.11.3

Caveats:

  1. I realize winston: ^3.0.0-rc0 is ahead of your winston: ^2.1.1 but wanted to bring it up since Winston 3 will be out eventually.

  2. The log groups/streams do not exist and the machine I am running on does not have permission to create them. So I fully expect an error. I'm just trying to understand error handling in general and how to keep my app from crashing in this case.

Caveats aside:
Do you think this is related to Winston 3? or am I doing something else wrong?

Thanks!

Hey, I've just tested the code with winston@2.1.1 and your code (which I presume is taken from examples/simple.js) works ok.

Error handling could be done using use winston's uncaughtException handler, or one that you provide. Best practices here. If you don't want errors to be console.erred then you can provide your own logging function, have a look at options for more.

You are by the way right in expecting the library to work with more up to date versions of winston. I will try my best to look into compatibilities problems in the weekend, and hopefully release a major version addressing them.

Thank you for using the library.

Thanks for your reply and pointing out winston's uncaughtException handler. I've updated my code to this:

const winston           = require('winston');
const winstonCloudwatch = require('winston-cloudwatch');

winston.add(new winstonCloudwatch({
    logGroupName: 'testing',
    logStreamName: 'first'
}));

// handle uncaught exceptions
winston.exceptions.handle(
    new winston.transports.File({ filename: './log/exceptions.log' })
);

winston.error('1');

However, now I am getting nothing in the console, nothing in ./log/exceptions.log and nothing in cloudwatch (<- this part is expected, as I mentioned)

I guess, to simplify the discussion...

Going back to my original code without the exception handler, how am I getting TypeError: callback is not a function?

I think that means I don't have an uncaughtException handler, but that is misleading since:

  • even then the error should go to console.error
  • the real error I am expecting is along the lines of unable to create cloudwatch log group or stream, or something to that effect

Should console.error (or my logfile in the case of the new code) report the inability to create cloudwatch logs, rather than TypeError: callback is not a function?

Thanks!

Ok, so I downgraded to winston: 2.4.0 and started getting something more like what I expected in the console.

{ UnrecognizedClientException: The security token included in the request is invalid.
    at Request.extractError (/vagrant/convertup/service-mail/node_modules/aws-sdk/lib/protocol/json.js:48:27)
    at Request.callListeners (/vagrant/convertup/service-mail/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at Request.emit (/vagrant/convertup/service-mail/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/vagrant/convertup/service-mail/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/vagrant/convertup/service-mail/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/vagrant/convertup/service-mail/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /vagrant/convertup/service-mail/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/vagrant/convertup/service-mail/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/vagrant/convertup/service-mail/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/vagrant/convertup/service-mail/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
  message: 'The security token included in the request is invalid.',
  code: 'UnrecognizedClientException',
  time: 2017-10-14T18:08:34.209Z,
  requestId: 'b1600a48-b10a-11e7-9cd3-b7a2197ab9b6',
  statusCode: 400,
  retryable: false,
  retryDelay: 66.79119486059494 }

I think we can put a pin in this issue and attribute it to incompatibility with winston ^3.0.0-rc0.

I'll be happy to revisit this and help you test for winston 3 when you're ready.

Yes agreed, let's revisit it by then.

Hi @lazywithclass, any insight into what is causing this?

I'd like to use this with an updated version of Winston, if possible. Older versions of Winston are causing problems in Typescript.

Hey @aneilbaboo we're waiting the stable for winston 3.0. There's a PR addressing the upgrade.

I think the code as is in that PR is working ok with the latest winston rc, one thing you could do is test if the problem happens if you use that code, or just wait until they are done with their testing.

@lazywithclass - ah, thanks for the pointer. That PR works for me.

@aneilbaboo great, I'll close this then.