MCPcopy Index your code
hub / github.com/nodejs/node / tryStringify

Function tryStringify

lib/internal/util/inspect.js:2752–2772  ·  view source on GitHub ↗
(arg)

Source from the content-addressed store, hash-verified

2750const firstErrorLine = (error) => StringPrototypeSplit(error.message, '\n', 1)[0];
2751let CIRCULAR_ERROR_MESSAGE;
2752function tryStringify(arg) {
2753 try {
2754 return JSONStringify(arg);
2755 } catch (err) {
2756 // Populate the circular error message lazily
2757 if (!CIRCULAR_ERROR_MESSAGE) {
2758 try {
2759 const a = {};
2760 a.a = a;
2761 JSONStringify(a);
2762 } catch (circularError) {
2763 CIRCULAR_ERROR_MESSAGE = firstErrorLine(circularError);
2764 }
2765 }
2766 if (err.name === 'TypeError' &&
2767 firstErrorLine(err) === CIRCULAR_ERROR_MESSAGE) {
2768 return '[Circular]';
2769 }
2770 throw err;
2771 }
2772}
2773
2774function format(...args) {
2775 return formatWithOptionsInternal(undefined, args);

Callers 1

Calls 1

firstErrorLineFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…