Skip to content

Commit 27a0f87

Browse files
cjihrigrvagg
authored andcommitted
doc: note util.isError() @@toStringTag limitations
util.isError() is the only remaining util.is*() method that depends on Object.prototype.toString() behavior. This commit notes the limitations of isError() related to @@toStringTag. Refs: #2201 PR-URL: #5414 Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 58bda8f commit 27a0f87

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

doc/api/util.markdown

+16
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,22 @@ util.isError({ name: 'Error', message: 'an error occurred' })
335335
// false
336336
```
337337

338+
Note that this method relies on `Object.prototype.toString()` behavior. It is
339+
possible to obtain an incorrect result when the `object` argument manipulates
340+
`@@toStringTag`.
341+
342+
```js
343+
// This example requires the `--harmony-tostring` flag
344+
const util = require('util');
345+
const obj = { name: 'Error', message: 'an error occurred' };
346+
347+
util.isError(obj);
348+
// false
349+
obj[Symbol.toStringTag] = 'Error';
350+
util.isError(obj);
351+
// true
352+
```
353+
338354
## util.isFunction(object)
339355

340356
Stability: 0 - Deprecated

0 commit comments

Comments
 (0)