{"record":{"id":"3de2f058cfc426dc","repo":"winstonjs/winston","slug":"exceptionstream-requires-a-transportstream-instanc","errorCode":null,"errorMessage":"ExceptionStream requires a TransportStream instance.","messagePattern":"ExceptionStream requires a TransportStream instance\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/winston/exception-stream.js","lineNumber":28,"sourceCode":"const { Writable } = require('readable-stream');\n\n/**\n * TODO: add class description.\n * @type {ExceptionStream}\n * @extends {Writable}\n */\nmodule.exports = class ExceptionStream extends Writable {\n  /**\n   * Constructor function for the ExceptionStream responsible for wrapping a\n   * TransportStream; only allowing writes of `info` objects with\n   * `info.exception` set to true.\n   * @param {!TransportStream} transport - Stream to filter to exceptions\n   */\n  constructor(transport) {\n    super({ objectMode: true });\n\n    if (!transport) {\n      throw new Error('ExceptionStream requires a TransportStream instance.');\n    }\n\n    // Remark (indexzero): we set `handleExceptions` here because it's the\n    // predicate checked in ExceptionHandler.prototype.__getExceptionHandlers\n    this.handleExceptions = true;\n    this.transport = transport;\n  }\n\n  /**\n   * Writes the info object to our transport instance if (and only if) the\n   * `exception` property is set on the info.\n   * @param {mixed} info - TODO: add param description.\n   * @param {mixed} enc - TODO: add param description.\n   * @param {mixed} callback - TODO: add param description.\n   * @returns {mixed} - TODO: add return description.\n   * @private\n   */\n  _write(info, enc, callback) {","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/winstonjs/winston/blob/ff0b79de8562bb322c390fbc82fe71c11f373428/lib/winston/exception-stream.js#L10-L46","documentation":"ExceptionStream is an objectMode Readable wrapper that filters exception entries to a given transport. Its constructor validates that a TransportStream instance was provided; without one the stream would have nothing to write exceptions to, so it throws immediately.","triggerScenarios":"Calling `new winston.ExceptionStream()` with no argument or a falsy value; passing something that is not a TransportStream (e.g. a plain object, a winston Logger, or a raw Node stream) in custom exception routing code.","commonSituations":"Custom uncaughtException plumbing where the transport variable failed to initialize; passing a logger instead of a transport; wiring transports after the stream was created.","solutions":["Pass a real transport instance: `new winston.ExceptionStream(new winston.transports.File({ filename: 'exceptions.log' }))`.","Create/configure the transport before constructing the stream.","Prefer `logger.exceptions.handle(transport)` so winston builds the ExceptionStream for you.","Verify the argument is a transport (has `log` method / `_writableState`) before constructing."],"exampleFix":"// before\nconst stream = new winston.ExceptionStream();\n\n// after\nconst stream = new winston.ExceptionStream(\n  new winston.transports.File({ filename: 'exceptions.log' })\n);","handlingStrategy":"type-guard","validationCode":"if (!transport || typeof transport.log !== 'function') {\n  throw new TypeError('ExceptionStream needs a TransportStream; got: ' + String(transport));\n}","typeGuard":"function isTransportStream(x) { return !!x && typeof x.log === 'function' && !!x._writableState && x._writableState.objectMode; }","tryCatchPattern":"let stream;\ntry {\n  stream = new winston.ExceptionStream(transport);\n} catch (err) {\n  if (err.message.startsWith('ExceptionStream requires')) {\n    stream = new winston.ExceptionStream(new winston.transports.File({ filename: 'exceptions.log' }));\n  } else { throw err; }\n}","preventionTips":["Construct transports before the streams that consume them","Prefer `logger.exceptions.handle(transport)` over manual ExceptionStream usage","Never pass a Logger where a TransportStream is expected","Type-check transport arguments in wrapper libraries"],"tags":["winston","argument-validation","streams","exceptions"],"backgroundTag":"missing-required-argument","analyzedSha":"ff0b79de8562bb322c390fbc82fe71c11f373428","analyzedAt":"2026-08-31T13:33:44.585Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}