Skip to content

Commit

Permalink
util: move util.isError to eol
Browse files Browse the repository at this point in the history
PR-URL: #52744
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
marco-ippolito authored and nodejs-github-bot committed May 6, 2024
1 parent b5cae4f commit dc37962
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 76 deletions.
9 changes: 5 additions & 4 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,9 @@ The `util.isDate()` API has been removed. Please use

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/52744
description: End-of-Life deprecation.
- version: v22.0.0
pr-url: https://github.com/nodejs/node/pull/50488
description: Runtime deprecation.
Expand All @@ -1092,9 +1095,9 @@ changes:
description: Documentation-only deprecation.
-->

Type: Runtime
Type: End-of-Life

The [`util.isError()`][] API is deprecated. Please use
The `util.isError()` API has been removed. Please use
`Object.prototype.toString(arg) === '[object Error]' || arg instanceof Error`
instead.

Expand Down Expand Up @@ -3809,8 +3812,6 @@ is deprecated to better align with recommendations per [NIST SP 800-38D][].
[`util.inspect()`]: util.md#utilinspectobject-options
[`util.inspect.custom`]: util.md#utilinspectcustom
[`util.isArray()`]: util.md#utilisarrayobject
[`util.isError()`]: util.md#utiliserrorobject
[`util.isFunction()`]: util.md#utilisfunctionobject
[`util.isPrimitive()`]: util.md#utilisprimitiveobject
[`util.log()`]: util.md#utillogstring
[`util.promisify`]: util.md#utilpromisifyoriginal
Expand Down
43 changes: 0 additions & 43 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -2950,47 +2950,6 @@ util.isArray({});
// Returns: false
```
### `util.isError(object)`
<!-- YAML
added: v0.6.0
deprecated: v4.0.0
-->
> Stability: 0 - Deprecated: Use [`util.types.isNativeError()`][] instead.
* `object` {any}
* Returns: {boolean}
Returns `true` if the given `object` is an [`Error`][]. Otherwise, returns
`false`.
```js
const util = require('node:util');

util.isError(new Error());
// Returns: true
util.isError(new TypeError());
// Returns: true
util.isError({ name: 'Error', message: 'an error occurred' });
// Returns: false
```
This method relies on `Object.prototype.toString()` behavior. It is
possible to obtain an incorrect result when the `object` argument manipulates
`@@toStringTag`.
```js
const util = require('node:util');
const obj = { name: 'Error', message: 'an error occurred' };

util.isError(obj);
// Returns: false
obj[Symbol.toStringTag] = 'Error';
util.isError(obj);
// Returns: true
```
### `util.isFunction(object)`
<!-- YAML
Expand Down Expand Up @@ -3094,7 +3053,6 @@ util.log('Timestamped message.');
[`ArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
[`DataView`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
[`Date`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
[`Error`]: errors.md#class-error
[`Float32Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
[`Float64Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
[`Int16Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
Expand Down Expand Up @@ -3127,7 +3085,6 @@ util.log('Timestamped message.');
[`util.promisify()`]: #utilpromisifyoriginal
[`util.types.isAnyArrayBuffer()`]: #utiltypesisanyarraybuffervalue
[`util.types.isArrayBuffer()`]: #utiltypesisarraybuffervalue
[`util.types.isNativeError()`]: #utiltypesisnativeerrorvalue
[`util.types.isSharedArrayBuffer()`]: #utiltypesissharedarraybuffervalue
[async function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
[built-in `Error` type]: https://tc39.es/ecma262/#sec-error-objects
Expand Down
15 changes: 0 additions & 15 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const {
ObjectDefineProperty,
ObjectGetOwnPropertyDescriptors,
ObjectKeys,
ObjectPrototypeToString,
ObjectSetPrototypeOf,
ObjectValues,
ReflectApply,
Expand Down Expand Up @@ -90,15 +89,6 @@ function lazyAbortController() {

let internalDeepEqual;

/**
* @deprecated since v4.0.0
* @param {any} e
* @returns {arg is Error}
*/
function isError(e) {
return ObjectPrototypeToString(e) === '[object Error]' || e instanceof Error;
}

/**
* @deprecated since v4.0.0
* @param {any} arg
Expand Down Expand Up @@ -354,11 +344,6 @@ module.exports = {
}
return internalDeepEqual(a, b);
},
isError: deprecate(isError,
'The `util.isError` API is deprecated. ' +
'Please use `ObjectPrototypeToString(e) === "[object Error]" ' +
'|| e instanceof Error` instead.',
'DEP0048'),
isFunction: deprecate(isFunction,
'The `util.isFunction` API is deprecated. Please use `typeof arg === "function"` instead.',
'DEP0049'),
Expand Down
14 changes: 0 additions & 14 deletions test/parallel/test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ assert.strictEqual(util.isArray(/regexp/), false);
assert.strictEqual(util.isArray(new Error()), false);
assert.strictEqual(util.isArray({ __proto__: Array.prototype }), false);

// isError
assert.strictEqual(util.isError(new Error()), true);
assert.strictEqual(util.isError(new TypeError()), true);
assert.strictEqual(util.isError(new SyntaxError()), true);
assert.strictEqual(util.isError(new (context('Error'))()), true);
assert.strictEqual(util.isError(new (context('TypeError'))()), true);
assert.strictEqual(util.isError(new (context('SyntaxError'))()), true);
assert.strictEqual(util.isError({}), false);
assert.strictEqual(util.isError({ name: 'Error', message: '' }), false);
assert.strictEqual(util.isError([]), false);
assert.strictEqual(util.isError({ __proto__: Error.prototype }), true);

// isPrimitive
assert.strictEqual(util.isPrimitive({}), false);
assert.strictEqual(util.isPrimitive(new Error()), false);
Expand All @@ -62,8 +50,6 @@ assert.strictEqual(util.isPrimitive(function() {}), false);
assert.strictEqual(util.isPrimitive(new Number(1)), false);
assert.strictEqual(util.isPrimitive(new String('bla')), false);
assert.strictEqual(util.isPrimitive(new Boolean(true)), false);
assert.strictEqual(util.isPrimitive(1), true);
assert.strictEqual(util.isPrimitive('bla'), true);
assert.strictEqual(util.isPrimitive(true), true);
assert.strictEqual(util.isPrimitive(undefined), true);
assert.strictEqual(util.isPrimitive(null), true);
Expand Down

0 comments on commit dc37962

Please sign in to comment.