@@ -168,6 +168,81 @@ describe('eventFromUnknownInput', () => {
168168 } ,
169169 } ) ;
170170 } ) ;
171+
172+ it ( 'add a synthetic stack trace to DOMException with empty stack traces if attachStacktrace is true' , async ( ) => {
173+ const exception = new DOMException ( 'The string did not match the expected pattern.' , 'SyntaxError' ) ;
174+ exception . stack = '' ;
175+
176+ const syntheticException = new Error ( 'Test message' ) ;
177+ const event = await eventFromUnknownInput ( defaultStackParser , exception , syntheticException , true ) ;
178+ expect ( event . exception ?. values ?. [ 0 ] ) . toEqual (
179+ expect . objectContaining ( {
180+ mechanism : { handled : true , synthetic : true , type : 'generic' } ,
181+ stacktrace : {
182+ frames : expect . arrayContaining ( [ expect . any ( Object ) , expect . any ( Object ) ] ) ,
183+ } ,
184+ type : 'Error' ,
185+ value : 'SyntaxError: The string did not match the expected pattern.' ,
186+ } ) ,
187+ ) ;
188+ } ) ;
189+
190+ it ( 'add a synthetic stack trace to DOMException without a stack traces property if attachStacktrace is true' , async ( ) => {
191+ const exception = new DOMException ( 'The string did not match the expected pattern.' , 'SyntaxError' ) ;
192+ delete exception . stack ;
193+
194+ const syntheticException = new Error ( 'Test message' ) ;
195+ const event = await eventFromUnknownInput ( defaultStackParser , exception , syntheticException , true ) ;
196+ expect ( event . exception ?. values ?. [ 0 ] ) . toEqual (
197+ expect . objectContaining ( {
198+ mechanism : { handled : true , synthetic : true , type : 'generic' } ,
199+ stacktrace : {
200+ frames : expect . arrayContaining ( [ expect . any ( Object ) , expect . any ( Object ) ] ) ,
201+ } ,
202+ type : 'Error' ,
203+ value : 'SyntaxError: The string did not match the expected pattern.' ,
204+ } ) ,
205+ ) ;
206+ } ) ;
207+
208+ it ( "doesn't add a synthetic stack trace to DOMException with empty stack traces if attachStacktrace is false" , async ( ) => {
209+ const exception = new DOMException ( 'The string did not match the expected pattern.' , 'SyntaxError' ) ;
210+ exception . stack = '' ;
211+
212+ const syntheticException = new Error ( 'Test message' ) ;
213+ const event = await eventFromUnknownInput ( defaultStackParser , exception , syntheticException , false ) ;
214+ expect ( event . exception ?. values ?. [ 0 ] ) . toEqual (
215+ {
216+ type : 'Error' ,
217+ value : 'SyntaxError: The string did not match the expected pattern.' ,
218+ } ,
219+ ) ;
220+ } ) ;
221+
222+ it ( "doesn't add a synthetic stack trace to DOMException with stack traces if attachStacktrace is true" , async ( ) => {
223+ const exception = new DOMException ( 'The string did not match the expected pattern.' , 'SyntaxError' ) ;
224+ exception . stack = 'SyntaxError\n at <anonymous>:1:2' ;
225+
226+ const syntheticException = new Error ( 'Test message' ) ;
227+ const event = await eventFromUnknownInput ( defaultStackParser , exception , syntheticException , true ) ;
228+ expect ( event . exception ?. values ?. [ 0 ] ) . toEqual (
229+ expect . objectContaining ( {
230+ stacktrace : {
231+ frames : [
232+ {
233+ colno : 2 ,
234+ filename : "<anonymous>" ,
235+ function : "?" ,
236+ in_app : true ,
237+ lineno : 1 ,
238+ } ,
239+ ] ,
240+ } ,
241+ type : 'SyntaxError' ,
242+ value : 'The string did not match the expected pattern.' ,
243+ } ) ,
244+ ) ;
245+ } ) ;
171246} ) ;
172247
173248describe ( 'extractMessage' , ( ) => {
0 commit comments