@@ -4033,3 +4033,27 @@ ${error.stack.split('\n').slice(1).join('\n')}`,
40334033 assert . match ( inspect ( DOMException . prototype ) , / ^ \[ o b j e c t D O M E x c e p t i o n \] \{ / ) ;
40344034 delete Error [ Symbol . hasInstance ] ;
40354035}
4036+
4037+ // Test that errors respect the depth option, same as other objects.
4038+ {
4039+ // At depth: -1, errors should be abbreviated like [Object] for plain objects.
4040+ assert . strictEqual ( inspect ( new Error ( 'msg' ) , { depth : - 1 } ) , '[Error: msg]' ) ;
4041+ assert . strictEqual ( inspect ( new TypeError ( 'bad' ) , { depth : - 1 } ) , '[TypeError: bad]' ) ;
4042+ assert . strictEqual ( inspect ( new RangeError ( 'oob' ) , { depth : - 1 } ) , '[RangeError: oob]' ) ;
4043+
4044+ // No message → just [ErrorName]
4045+ assert . strictEqual ( inspect ( new Error ( ) , { depth : - 1 } ) , '[Error]' ) ;
4046+
4047+ // Custom name property
4048+ const customErr = new Error ( 'test' ) ;
4049+ customErr . name = 'MyError' ;
4050+ assert . strictEqual ( inspect ( customErr , { depth : - 1 } ) , '[MyError: test]' ) ;
4051+
4052+ // Errors nested inside an object at depth: 0 should be abbreviated,
4053+ // just as nested plain objects are shown as [Object].
4054+ const wrapper = { err : new TypeError ( 'oops' ) , obj : { a : 1 } } ;
4055+ const result = inspect ( wrapper , { depth : 0 } ) ;
4056+ assert . match ( result , / \[ T y p e E r r o r : o o p s \] / ) ;
4057+ assert . match ( result , / \[ O b j e c t \] / ) ;
4058+ assert ( ! result . includes ( ' at ' ) , 'stack trace should not appear at depth 0' ) ;
4059+ }
0 commit comments