Skip to content

Commit

Permalink
Move AggregateError to primordials
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Jan 1, 2025
1 parent c820e2b commit f66337f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lib/ours/errors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { format, inspect } = require('./util/inspect')
const { AggregateError: CustomAggregateError } = require('./util')
const { AggregateError: CustomAggregateError } = require('./primordials')

/*
This file is a reduced and adapted version of the main lib/internal/errors.js file defined at
Expand Down
17 changes: 17 additions & 0 deletions lib/ours/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,24 @@
Don't try to replace with the original file and keep it up to date with the upstream file.
*/

// This is a simplified version of AggregateError
class AggregateError extends Error {
constructor(errors) {
if (!Array.isArray(errors)) {
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`)
}
let message = ''
for (let i = 0; i < errors.length; i++) {
message += ` ${errors[i].stack}\n`
}
super(message)
this.name = 'AggregateError'
this.errors = errors
}
}
module.exports = {
AggregateError,
ArrayIsArray(self) {
return Array.isArray(self)
},
Expand Down
18 changes: 1 addition & 17 deletions lib/ours/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { format, inspect } = require('./util/inspect')
const {
codes: { ERR_INVALID_ARG_TYPE }
} = require('./errors')
const { kResistStopPropagation, SymbolDispose } = require('./primordials')
const { kResistStopPropagation, AggregateError, SymbolDispose } = require('./primordials')
const AbortSignal = globalThis.AbortSignal || require('abort-controller').AbortSignal
const AbortController = globalThis.AbortController || require('abort-controller').AbortController
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor
Expand All @@ -32,22 +32,6 @@ const validateFunction = (value, name) => {
throw new ERR_INVALID_ARG_TYPE(name, 'Function', value)
}
}

// This is a simplified version of AggregateError
class AggregateError extends Error {
constructor(errors) {
if (!Array.isArray(errors)) {
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`)
}
let message = ''
for (let i = 0; i < errors.length; i++) {
message += ` ${errors[i].stack}\n`
}
super(message)
this.name = 'AggregateError'
this.errors = errors
}
}
module.exports = {
AggregateError,
kEmptyObject: Object.freeze({}),
Expand Down
2 changes: 1 addition & 1 deletion src/errors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { format, inspect } = require('./util/inspect')
const { AggregateError: CustomAggregateError } = require('./util')
const { AggregateError: CustomAggregateError } = require('./primordials')

/*
This file is a reduced and adapted version of the main lib/internal/errors.js file defined at
Expand Down
19 changes: 19 additions & 0 deletions src/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,26 @@
Don't try to replace with the original file and keep it up to date with the upstream file.
*/

// This is a simplified version of AggregateError
class AggregateError extends Error {
constructor(errors) {
if (!Array.isArray(errors)) {
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`)
}

let message = ''
for (let i = 0; i < errors.length; i++) {
message += ` ${errors[i].stack}\n`
}

super(message)
this.name = 'AggregateError'
this.errors = errors
}
}

module.exports = {
AggregateError,
ArrayIsArray(self) {
return Array.isArray(self)
},
Expand Down
20 changes: 1 addition & 19 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { format, inspect } = require('./util/inspect')
const {
codes: { ERR_INVALID_ARG_TYPE }
} = require('./errors')
const { kResistStopPropagation, SymbolDispose } = require('./primordials')
const { kResistStopPropagation, AggregateError, SymbolDispose } = require('./primordials')
const AbortSignal = globalThis.AbortSignal || require('abort-controller').AbortSignal
const AbortController = globalThis.AbortController || require('abort-controller').AbortController

Expand Down Expand Up @@ -34,24 +34,6 @@ const validateFunction = (value, name) => {
}
}

// This is a simplified version of AggregateError
class AggregateError extends Error {
constructor(errors) {
if (!Array.isArray(errors)) {
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`)
}

let message = ''
for (let i = 0; i < errors.length; i++) {
message += ` ${errors[i].stack}\n`
}

super(message)
this.name = 'AggregateError'
this.errors = errors
}
}

module.exports = {
AggregateError,
kEmptyObject: Object.freeze({}),
Expand Down

0 comments on commit f66337f

Please sign in to comment.