mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 09:08:46 +00:00

ERR_INVALID_ARG_TYPE is the most common error used throughout the code base. This improves the error message by providing more details to the user and by indicating more precisely which values are allowed ones and which ones are not. It adds the actual input to the error message in case it's a primitive. If it's a class instance, it'll print the class name instead of "object" and "falsy" or similar entries are not named "type" anymore. PR-URL: https://github.com/nodejs/node/pull/29675 Reviewed-By: Rich Trott <rtrott@gmail.com>
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
if (!common.isMainThread)
|
|
common.skip('process.chdir is not available in Workers');
|
|
|
|
const { writeHeapSnapshot, getHeapSnapshot } = require('v8');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
|
process.chdir(tmpdir.path);
|
|
|
|
{
|
|
writeHeapSnapshot('my.heapdump');
|
|
fs.accessSync('my.heapdump');
|
|
}
|
|
|
|
{
|
|
const heapdump = writeHeapSnapshot();
|
|
assert.strictEqual(typeof heapdump, 'string');
|
|
fs.accessSync(heapdump);
|
|
}
|
|
|
|
[1, true, {}, [], null, Infinity, NaN].forEach((i) => {
|
|
common.expectsError(() => writeHeapSnapshot(i), {
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "path" argument must be of type string or an instance of ' +
|
|
'Buffer or URL.' +
|
|
common.invalidArgTypeHelper(i)
|
|
});
|
|
});
|
|
|
|
{
|
|
let data = '';
|
|
const snapshot = getHeapSnapshot();
|
|
snapshot.setEncoding('utf-8');
|
|
snapshot.on('data', common.mustCallAtLeast((chunk) => {
|
|
data += chunk.toString();
|
|
}));
|
|
snapshot.on('end', common.mustCall(() => {
|
|
JSON.parse(data);
|
|
}));
|
|
}
|