Repository: nodejs/node
File: test/parallel/test-util-inspect.js (JavaScript)

Code before:

    const innerError = recursions > 0 ?
      getRecursiveThrowingError(recursions - 1) :
      terminalError;

    const throwingGetter = {
      __proto__: null,
      get() {
        throw innerError;
      },
      configurable: true,
      enumerable: true,
    };

    Object.defineProperties(badError, {
      message: throwingGetter,
      stack: throwingGetter,
    });

    return badError;
  }

  const badRecursiveError = getRecursiveThrowingError(3);
  const thrower = {
    get foo() { throw badRecursiveError; }
  };

  assert.strictEqual(
    inspect(thrower, { getters: true, depth: 2 }),
    '{\n' +
    '  foo: [Getter: <Inspection threw ([object Error] {\n' +
    '    stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
    '      stack: [Getter/Setter: <Inspection threw ([Error])>],\n' +
    '      message: [Getter: <Inspection threw ([Error])>]\n' +
    '    })>],\n' +
    '    message: [Getter: <Inspection threw ([object Error] {\n' +
    '      stack: [Getter/Setter: <Inspection threw ([Error])>],\n' +
    '      message: [Getter: <Inspection threw ([Error])>]\n' +
    '    })>]\n' +
    '  })>]\n' +
    '}'
  );

  assert.strictEqual(
    inspect(thrower, { getters: true, depth: 4 }),
    '{\n' +
    '  foo: [Getter: <Inspection threw ([object Error] {\n' +
    '    stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
    '      stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
    '        stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
    '          stack: [Getter/Setter: <Inspection threw (Error: Oops\n' +

Review comment (suggestion):
```suggestion
  const recursivelyThrowingErrorDesc = {
    __proto__: null,
    get() { throw createRecursivelyThrowingError(); },
    configurable: true,
    enumerable: true,
  };
  const createRecursivelyThrowingError = () =>
    Object.defineProperties(new Error(), {
        cause: recursivelyThrowingErrorDesc,
        name: recursivelyThrowingErrorDesc,
        message: recursivelyThrowingErrorDesc,
        stack: recursivelyThrowingErrorDesc,
    });

  const thrower = Object.defineProperty({}, 'foo', recursivelyThrowingErrorDesc);
```

Code after:
  };
  const createRecursivelyThrowingError = () =>
    Object.defineProperties(new Error(), {
      cause: recursivelyThrowingErrorDesc,
      name: recursivelyThrowingErrorDesc,
      message: recursivelyThrowingErrorDesc,
      stack: recursivelyThrowingErrorDesc,
    });
  const thrower = Object.defineProperty({}, 'foo', recursivelyThrowingErrorDesc);

  assert.strictEqual(
    inspect(thrower, { getters: true, depth: 1 }),
    '{\n' +
    '  foo: [Getter: <Inspection threw ([object Error] {\n' +
    '    stack: [Getter/Setter: <Inspection threw ([Error])>],\n' +
    '    cause: [Getter: <Inspection threw ([Error])>],\n' +
    '    name: [Getter: <Inspection threw ([Error])>],\n' +
    '    message: [Getter: <Inspection threw ([Error])>]\n' +
    '  })>]\n' +
    '}'
  );

  [{ getters: true, depth: 2 }, { getters: true }].forEach((options) => {
    assert.strictEqual(
      inspect(thrower, options),
      '{\n' +
      '  foo: [Getter: <Inspection threw ([object Error] {\n' +
      '    stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
      '      stack: [Getter/Setter: <Inspection threw ([Error])>],\n' +
      '      cause: [Getter: <Inspection threw ([Error])>],\n' +
      '      name: [Getter: <Inspection threw ([Error])>],\n' +
      '      message: [Getter: <Inspection threw ([Error])>]\n' +
      '    })>],\n' +
      '    cause: [Getter: <Inspection threw ([object Error] {\n' +
      '      stack: [Getter/Setter: <Inspection threw ([Error])>],\n' +
      '      cause: [Getter: <Inspection threw ([Error])>],\n' +
      '      name: [Getter: <Inspection threw ([Error])>],\n' +
      '      message: [Getter: <Inspection threw ([Error])>]\n' +
      '    })>],\n' +
      '    name: [Getter: <Inspection threw ([object Error] {\n' +
      '      stack: [Getter/Setter: <Inspection threw ([Error])>],\n' +
      '      cause: [Getter: <Inspection threw ([Error])>],\n' +
      '      name: [Getter: <Inspection threw ([Error])>],\n' +
      '      message: [Getter: <Inspection threw ([Error])>]\n' +
      '    })>],\n' +
      '    message: [Getter: <Inspection threw ([object Error] {\n' +
      '      stack: [Getter/Setter: <Inspection threw ([Error])>],\n' +
      '      cause: [Getter: <Inspection threw ([Error])>],\n' +
      '      name: [Getter: <Inspection threw ([Error])>],\n' +
      '      message: [Getter: <Inspection threw ([Error])>]\n' +
      '    })>]\n' +