Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1542,11 +1542,6 @@ function reduceToSingleString(
return `${braces[0]}${ln}${join(output, `,\n${indentation} `)} ${braces[1]}`;
}

function format(...args) {
return formatWithOptions(undefined, ...args);
}


const firstErrorLine = (error) => error.message.split('\n')[0];
let CIRCULAR_ERROR_MESSAGE;
function tryStringify(arg) {
Expand All @@ -1569,7 +1564,19 @@ function tryStringify(arg) {
}
}

function format(...args) {
return formatWithOptionsInternal(undefined, ...args);
}

function formatWithOptions(inspectOptions, ...args) {
if (typeof inspectOptions !== 'object' || inspectOptions === null) {
throw new ERR_INVALID_ARG_TYPE(
'inspectOptions', 'object', inspectOptions);
}
return formatWithOptionsInternal(inspectOptions, ...args);
}

function formatWithOptionsInternal(inspectOptions, ...args) {
const first = args[0];
let a = 0;
let str = '';
Expand Down
17 changes: 17 additions & 0 deletions test/parallel/test-util-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,20 @@ assert.strictEqual(
),
'[ 1, [Object] ]'
);

[
undefined,
null,
false,
5n,
5,
'test',
Symbol()
].forEach((invalidOptions) => {
assert.throws(() => {
util.formatWithOptions(invalidOptions, { a: true });
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: /"inspectOptions".+object/
});
});