MCPcopy Index your code
hub / github.com/nodejs/node / errorOrDestroy

Function errorOrDestroy

lib/internal/streams/destroy.js:204–242  ·  view source on GitHub ↗
(stream, err, sync)

Source from the content-addressed store, hash-verified

202}
203
204function errorOrDestroy(stream, err, sync) {
205 // We have tests that rely on errors being emitted
206 // in the same tick, so changing this is semver major.
207 // For now when you opt-in to autoDestroy we allow
208 // the error to be emitted nextTick. In a future
209 // semver major update we should change the default to this.
210
211 const r = stream._readableState;
212 const w = stream._writableState;
213
214 if (
215 (w && (w[kState] ? (w[kState] & kDestroyed) !== 0 : w.destroyed)) ||
216 (r && (r[kState] ? (r[kState] & kDestroyed) !== 0 : r.destroyed))
217 ) {
218 return this;
219 }
220
221 if (
222 (r && (r[kState] & kAutoDestroy) !== 0) ||
223 (w && (w[kState] & kAutoDestroy) !== 0)
224 ) {
225 stream.destroy(err);
226 } else if (err) {
227 // Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
228 err.stack; // eslint-disable-line no-unused-expressions
229
230 if (w && (w[kState] & kErrored) === 0) {
231 w.errored = err;
232 }
233 if (r && (r[kState] & kErrored) === 0) {
234 r.errored = err;
235 }
236 if (sync) {
237 process.nextTick(emitErrorNT, stream, err);
238 } else {
239 emitErrorNT(stream, err);
240 }
241 }
242}
243
244function construct(stream, cb) {
245 if (typeof stream._construct !== 'function') {

Callers 13

writable.jsFile · 0.85
_writeFunction · 0.85
onwriteErrorFunction · 0.85
onwriteFunction · 0.85
onFinishFunction · 0.85
onConstructFunction · 0.85
readable.jsFile · 0.85
onerrorFunction · 0.85

Calls 2

emitErrorNTFunction · 0.70
destroyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…