mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 16:22:29 +00:00

If there is no handler for `.emit('error', value)` and `value` is not an `Error` object, we currently just call `.toString()` on it. Almost always, using `util.inspect()` provides better information for diagnostic purposes, so prefer to use that instead. Refs: https://github.com/nodejs/help/issues/1729 PR-URL: https://github.com/nodejs/node/pull/25621 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
37 lines
763 B
JavaScript
37 lines
763 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const EventEmitter = require('events');
|
|
const util = require('util');
|
|
|
|
const EE = new EventEmitter();
|
|
|
|
common.expectsError(
|
|
() => EE.emit('error', 'Accepts a string'),
|
|
{
|
|
code: 'ERR_UNHANDLED_ERROR',
|
|
type: Error,
|
|
message: "Unhandled error. ('Accepts a string')"
|
|
}
|
|
);
|
|
|
|
common.expectsError(
|
|
() => EE.emit('error', { message: 'Error!' }),
|
|
{
|
|
code: 'ERR_UNHANDLED_ERROR',
|
|
type: Error,
|
|
message: "Unhandled error. ({ message: 'Error!' })"
|
|
}
|
|
);
|
|
|
|
common.expectsError(
|
|
() => EE.emit('error', {
|
|
message: 'Error!',
|
|
[util.inspect.custom]() { throw new Error(); }
|
|
}),
|
|
{
|
|
code: 'ERR_UNHANDLED_ERROR',
|
|
type: Error,
|
|
message: 'Unhandled error. ([object Object])'
|
|
}
|
|
);
|