{"record":{"id":"c8e1cde158191723","repo":"winstonjs/winston","slug":"rejectionstream-requires-a-transportstream-instanc","errorCode":null,"errorMessage":"RejectionStream requires a TransportStream instance.","messagePattern":"RejectionStream requires a TransportStream instance\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/winston/rejection-stream.js","lineNumber":28,"sourceCode":"const { Writable } = require('readable-stream');\n\n/**\n * TODO: add class description.\n * @type {RejectionStream}\n * @extends {Writable}\n */\nmodule.exports = class RejectionStream extends Writable {\n  /**\n   * Constructor function for the RejectionStream responsible for wrapping a\n   * TransportStream; only allowing writes of `info` objects with\n   * `info.rejection` set to true.\n   * @param {!TransportStream} transport - Stream to filter to rejections\n   */\n  constructor(transport) {\n    super({ objectMode: true });\n\n    if (!transport) {\n      throw new Error('RejectionStream requires a TransportStream instance.');\n    }\n\n    this.handleRejections = true;\n    this.transport = transport;\n  }\n\n  /**\n   * Writes the info object to our transport instance if (and only if) the\n   * `rejection` 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) {\n    if (info.rejection) {\n      return this.transport.log(info, callback);","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/winstonjs/winston/blob/ff0b79de8562bb322c390fbc82fe71c11f373428/lib/winston/rejection-stream.js#L10-L46","documentation":"RejectionStream mirrors ExceptionStream: an objectMode stream that filters unhandled-rejection entries to a given TransportStream. Its constructor throws immediately when no transport is supplied, because the stream would have nowhere to send rejection records.","triggerScenarios":"Calling `new winston.RejectionStream()` with no argument or falsy value; passing a non-transport (plain object, logger, raw stream) in custom unhandledRejection routing.","commonSituations":"Custom rejection pipelines where the transport wasn't initialized yet; confusing Logger with TransportStream arguments; hand-rolled rejection handling in libraries built on winston.","solutions":["Pass a transport instance: `new winston.RejectionStream(new winston.transports.File({ filename: 'rejections.log' }))`.","Create the transport before constructing the stream.","Prefer `logger.rejections.handle(transport)` so winston constructs the stream for you.","Assert the argument is a transport before constructing."],"exampleFix":"// before\nconst stream = new winston.RejectionStream();\n\n// after\nconst stream = new winston.RejectionStream(\n  new winston.transports.File({ filename: 'rejections.log' })\n);","handlingStrategy":"type-guard","validationCode":"if (!transport || typeof transport.log !== 'function') {\n  throw new TypeError('RejectionStream 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.RejectionStream(transport);\n} catch (err) {\n  if (err.message.startsWith('RejectionStream requires')) {\n    stream = new winston.RejectionStream(new winston.transports.File({ filename: 'rejections.log' }));\n  } else { throw err; }\n}","preventionTips":["Prefer `logger.rejections.handle(transport)` over manual RejectionStream usage","Construct transports before streams that wrap them","Do not pass a Logger where a TransportStream is required","Validate transport arguments in wrapper libraries"],"tags":["winston","argument-validation","streams","promise-rejections"],"backgroundTag":"missing-required-argument","analyzedSha":"ff0b79de8562bb322c390fbc82fe71c11f373428","analyzedAt":"2026-08-31T13:33:44.585Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}