Skip to content
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

Returning undefined from a formatter sometimes results in transport exception. #56

Open
djencks opened this issue Nov 16, 2019 · 0 comments

Comments

@djencks
Copy link

djencks commented Nov 16, 2019

From the documentation I suspect this might belong in winston core, but the exception is showing up in transport.

With this configuration:

const winston = require('winston')
const logger = winston.loggers.get('Antora')
...
  logger.configure({
    format: winston.format((info, opts) => {
      messages.push(info)
      return undefined
    }
    )(),
    transports: [new winston.transports.Console({ level: 'error' })],
  })

there is one circumstance out of 143 in which I get:

     TypeError: Cannot read property 'exception' of undefined
      at Console._write (node_modules/winston-transport/index.js:69:28)
      at doWrite (node_modules/readable-stream/lib/_stream_writable.js:428:64)
      at writeOrBuffer (node_modules/readable-stream/lib/_stream_writable.js:417:5)
      at Console.Writable.write (node_modules/readable-stream/lib/_stream_writable.js:334:11)
      at DerivedLogger.ondata (node_modules/winston/node_modules/readable-stream/lib/_stream_readable.js:662:20)
      at addChunk (node_modules/winston/node_modules/readable-stream/lib/_stream_readable.js:297:12)
      at readableAddChunk (node_modules/winston/node_modules/readable-stream/lib/_stream_readable.js:279:11)
      at DerivedLogger.Readable.push (node_modules/winston/node_modules/readable-stream/lib/_stream_readable.js:240:10)
      at DerivedLogger.Transform.push (node_modules/winston/node_modules/readable-stream/lib/_stream_transform.js:139:32)
      at DerivedLogger._transform (node_modules/winston/lib/winston/logger.js:305:12)
      at DerivedLogger.Transform._read (node_modules/winston/node_modules/readable-stream/lib/_stream_transform.js:177:10)
      at DerivedLogger.Transform._write (node_modules/winston/node_modules/readable-stream/lib/_stream_transform.js:164:83)
      at doWrite (node_modules/winston/node_modules/readable-stream/lib/_stream_writable.js:405:139)
      at writeOrBuffer (node_modules/winston/node_modules/readable-stream/lib/_stream_writable.js:394:5)
      at DerivedLogger.Writable.write (node_modules/winston/node_modules/readable-stream/lib/_stream_writable.js:303:11)
      at DerivedLogger.log (node_modules/winston/lib/winston/logger.js:210:12)
      at Object.add (packages/asciidoc-loader/lib/load-asciidoc.js:51:19)
      at Object.<anonymous> (node_modules/asciidoctor.js/dist/node/asciidoctor.js:19896:33)
      at Opal.send (node_modules/opal-runtime/src/opal.js:1660:19)
      at Object.$$error (node_modules/asciidoctor.js/dist/node/asciidoctor.js:1458:14)
      at $PreprocessorReader.$$resolve_include_path (node_modules/asciidoctor.js/dist/node/asciidoctor.js:13638:28)
      at $PreprocessorReader.$$preprocess_include_directive (node_modules/asciidoctor.js/dist/node/asciidoctor.js:13292:21)
      at $PreprocessorReader.$$process_line (node_modules/asciidoctor.js/dist/node/asciidoctor.js:13092:37)
      at $PreprocessorReader.$$peek_line (node_modules/asciidoctor.js/dist/node/asciidoctor.js:12562:41)
      at Opal.send (node_modules/opal-runtime/src/opal.js:1660:19)
      at $PreprocessorReader.$$peek_line (node_modules/asciidoctor.js/dist/node/asciidoctor.js:13149:29)
      at $PreprocessorReader.$$skip_blank_lines (node_modules/asciidoctor.js/dist/node/asciidoctor.js:12683:42)
      at Function.$$next_section (node_modules/asciidoctor.js/dist/node/asciidoctor.js:9146:35)
      at Function.$$parse (node_modules/asciidoctor.js/dist/node/asciidoctor.js:8760:23)
      at $Document.$$parse (node_modules/asciidoctor.js/dist/node/asciidoctor.js:7357:34)
      at /Users/david/projects/antora/antora/node_modules/asciidoctor.js/dist/node/asciidoctor.js:19550:66
      at Function.$$load (node_modules/asciidoctor.js/dist/node/asciidoctor.js:19551:28)
      at Function.$$convert (node_modules/asciidoctor.js/dist/node/asciidoctor.js:19673:20)
      at Function.Asciidoctor.convert (node_modules/asciidoctor.js/dist/node/asciidoctor.js:20027:21)
      at captureStderr (packages/asciidoc-loader/test/load-asciidoc-test.js:107:62)
      at captureStderr (packages/asciidoc-loader/test/load-asciidoc-test.js:48:23)
      at Context.it (packages/asciidoc-loader/test/load-asciidoc-test.js:107:30)

From the documentation, I expect that since the formatter returns 'undefined', a falsy value, nothing further would happen with the message.

Returning any of the other falsy values, null, NaN, 0, '', false, all work as expected.

Changing line 69ff to

TransportStream.prototype._write = function _write(info, enc, callback) {
  if (this.silent || (info && info.exception === true && !this.handleExceptions)) {
    return callback(null);
  }

ought to fix the issue, but I suspect this is not the correct solution.

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

No branches or pull requests

1 participant