From 1d5e727005e84a888a6c8accf1212ad273f0d6aa Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Fri, 21 Nov 2025 11:07:09 +0000 Subject: [PATCH] warn when util.inspect() truncated output --- packages/cli-repl/src/format-output.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/cli-repl/src/format-output.ts b/packages/cli-repl/src/format-output.ts index bd6971aa4a..0db60bd847 100644 --- a/packages/cli-repl/src/format-output.ts +++ b/packages/cli-repl/src/format-output.ts @@ -26,6 +26,7 @@ export type FormatOptions = { showStackTraces?: boolean; bugReportErrorMessageInfo?: string; allowControlCharacters?: boolean; + warnTruncatedOutput?: boolean; }; // eslint-disable-next-line no-control-regex @@ -160,7 +161,7 @@ Use db.getCollection('system.profile').find() to show raw profile entries.`, }); } - return formatSimpleType(value, options); + return formatSimpleType(value, { ...options, warnTruncatedOutput: true }); } function formatSimpleType(output: any, options: FormatOptions): string { @@ -173,7 +174,19 @@ function formatSimpleType(output: any, options: FormatOptions): string { } if (typeof output === 'undefined') return ''; - return inspect(output, options); + let result = inspect(output, options); + if (options.warnTruncatedOutput) { + if ( + /(\d+ more item)|(\d+ more character)|(\[Object\])|(\[Array\])/.test( + result + ) + ) { + result += + '\nWarning: The output might be truncated.' + + '\nTo see more use util.inspect() with custom options or configure depth, maxArrayLength and maxStringLength config options.'; + } + } + return result; } function formatCollections(