From 2bfe185c3fb3b9f5280f01bdd53b81d998d297e0 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 6 Feb 2021 08:03:04 -0800 Subject: [PATCH] util: use assert for unreachable code Great effort is taken to keep `util.inspect()` from throwing while inspecting a linked list or other items that require recursion. It is likely still possible at this time to cause a throw with prototype pollution, but that will change soon when the code is modified to use primordials. This commit instructs our coverage to not be concerned about not being able to reach the throwing-an-error code and changes the throw there to an assert so users will be instructed to open a bug with Node.js should they manage to cause the code to throw. PR-URL: https://github.com/nodejs/node/pull/37249 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Antoine du Hamel Reviewed-By: Darshan Sen --- lib/internal/util/inspect.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index cf4660b1f2d4d6..7845ee20ae8459 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -1386,7 +1386,8 @@ function handleMaxCallStackSize(ctx, err, constructorName, indentationLvl) { 'special' ); } - throw err; + /* c8 ignore next */ + assert.fail(err.stack); } function formatNumber(fn, value) {