@@ -23,6 +23,14 @@ describe('breakpoints', function () {
2323 * }}
2424 */
2525 let sessionMock
26+ /**
27+ * @type {{
28+ * debug: sinon.SinonStub;
29+ * error: sinon.SinonStub;
30+ * '@noCallThru ': boolean;
31+ * }}
32+ */
33+ let logMock
2634 /**
2735 * @type {{
2836 * findScriptFromPartialPath: sinon.SinonStub;
@@ -77,6 +85,12 @@ describe('breakpoints', function () {
7785 '@noCallThru' : true ,
7886 }
7987
88+ logMock = {
89+ debug : sinon . stub ( ) ,
90+ error : sinon . stub ( ) ,
91+ '@noCallThru' : true ,
92+ }
93+
8094 stateMock = {
8195 findScriptFromPartialPath : sinon . stub ( ) . returns ( {
8296 url : 'file:///path/to/test.js' ,
@@ -95,6 +109,7 @@ describe('breakpoints', function () {
95109 breakpoints = proxyquire ( '../../../src/debugger/devtools_client/breakpoints' , {
96110 './session' : sessionMock ,
97111 './state' : stateMock ,
112+ './log' : logMock ,
98113 } )
99114 } )
100115
@@ -453,6 +468,57 @@ describe('breakpoints', function () {
453468 } )
454469 } )
455470
471+ it ( 'should wrap errors when replacing a breakpoint while adding a probe fails' , async function ( ) {
472+ await addProbe ( )
473+ sessionMock . post . resetHistory ( )
474+
475+ const cause = new Error ( 'inspector failure' )
476+ sessionMock . post . callsFake ( ( method , { location } = { } ) => {
477+ if ( method === 'Debugger.removeBreakpoint' ) {
478+ return Promise . reject ( cause )
479+ }
480+ if ( method === 'Debugger.setBreakpoint' ) {
481+ return Promise . resolve ( {
482+ breakpointId : `bp-${ location . scriptId } :${ location . lineNumber } :${ location . columnNumber } ` ,
483+ } )
484+ }
485+ return Promise . resolve ( { } )
486+ } )
487+
488+ await assert . rejects (
489+ addProbe ( { id : 'probe-2' } ) ,
490+ ( err ) => {
491+ assert ( err instanceof Error )
492+ assert . strictEqual ( err . message , 'Error replacing breakpoint while adding probe probe-2 (version: 1)' )
493+ assert . strictEqual ( err . cause , cause )
494+ return true
495+ }
496+ )
497+ } )
498+
499+ it ( 'should wrap errors when setting a replacement breakpoint while adding a probe fails' , async function ( ) {
500+ await addProbe ( )
501+ sessionMock . post . resetHistory ( )
502+
503+ const cause = new Error ( 'inspector failure' )
504+ sessionMock . post . callsFake ( ( method , { location } = { } ) => {
505+ if ( method === 'Debugger.setBreakpoint' ) {
506+ return Promise . reject ( cause )
507+ }
508+ return Promise . resolve ( { } )
509+ } )
510+
511+ await assert . rejects (
512+ addProbe ( { id : 'probe-2' } ) ,
513+ ( err ) => {
514+ assert ( err instanceof Error )
515+ assert . strictEqual ( err . message , 'Error setting breakpoint while adding probe probe-2 (version: 1)' )
516+ assert . strictEqual ( err . cause , cause )
517+ return true
518+ }
519+ )
520+ } )
521+
456522 describe ( 'captureExpressions' , function ( ) {
457523 it ( 'should compile capture expressions' , async function ( ) {
458524 await addProbe ( {
@@ -632,6 +698,35 @@ describe('breakpoints', function () {
632698 sinon . assert . calledThrice ( sessionMock . post )
633699 } )
634700
701+ it ( 'should log and continue if removing a probe from the runtime sampler fails' , async function ( ) {
702+ await addProbe ( )
703+ sessionMock . post . resetHistory ( )
704+ logMock . error . resetHistory ( )
705+
706+ const cause = new Error ( 'runtime failure' )
707+ sessionMock . post . callsFake ( ( method , { location } = { } ) => {
708+ if ( method === 'Runtime.evaluate' ) {
709+ return Promise . reject ( cause )
710+ }
711+ if ( method === 'Debugger.setBreakpoint' ) {
712+ return Promise . resolve ( {
713+ breakpointId : `bp-${ location . scriptId } :${ location . lineNumber } :${ location . columnNumber } ` ,
714+ } )
715+ }
716+ return Promise . resolve ( { } )
717+ } )
718+
719+ await breakpoints . removeBreakpoint ( { id : 'probe-1' } )
720+
721+ sinon . assert . calledWith (
722+ logMock . error ,
723+ '[debugger:devtools_client] Error removing probe %s from sampler' ,
724+ 'probe-1' ,
725+ cause
726+ )
727+ sinon . assert . calledWith ( sessionMock . post . secondCall , 'Debugger.disable' )
728+ } )
729+
635730 describe ( 'update breakpoint when removing one of multiple probes at the same location' , function ( ) {
636731 it ( 'no conditions' , async function ( ) {
637732 await addProbe ( )
@@ -792,6 +887,59 @@ describe('breakpoints', function () {
792887 } )
793888 sinon . assert . calledThrice ( sessionMock . post )
794889 } )
890+
891+ it ( 'should wrap errors when removing the existing breakpoint fails' , async function ( ) {
892+ await addProbe ( )
893+ await addProbe ( { id : 'probe-2' } )
894+ sessionMock . post . resetHistory ( )
895+
896+ const cause = new Error ( 'inspector failure' )
897+ sessionMock . post . callsFake ( ( method , { location } = { } ) => {
898+ if ( method === 'Debugger.removeBreakpoint' ) {
899+ return Promise . reject ( cause )
900+ }
901+ if ( method === 'Debugger.setBreakpoint' ) {
902+ return Promise . resolve ( {
903+ breakpointId : `bp-${ location . scriptId } :${ location . lineNumber } :${ location . columnNumber } ` ,
904+ } )
905+ }
906+ return Promise . resolve ( { } )
907+ } )
908+
909+ await assert . rejects (
910+ breakpoints . removeBreakpoint ( { id : 'probe-1' } ) ,
911+ ( err ) => {
912+ assert ( err instanceof Error )
913+ assert . strictEqual ( err . message , 'Error replacing breakpoint after removing probe from script-1:10:0' )
914+ assert . strictEqual ( err . cause , cause )
915+ return true
916+ }
917+ )
918+ } )
919+
920+ it ( 'should wrap errors when setting the replacement breakpoint fails' , async function ( ) {
921+ await addProbe ( )
922+ await addProbe ( { id : 'probe-2' } )
923+ sessionMock . post . resetHistory ( )
924+
925+ const cause = new Error ( 'inspector failure' )
926+ sessionMock . post . callsFake ( ( method ) => {
927+ if ( method === 'Debugger.setBreakpoint' ) {
928+ return Promise . reject ( cause )
929+ }
930+ return Promise . resolve ( { } )
931+ } )
932+
933+ await assert . rejects (
934+ breakpoints . removeBreakpoint ( { id : 'probe-1' } ) ,
935+ ( err ) => {
936+ assert ( err instanceof Error )
937+ assert . strictEqual ( err . message , 'Error setting breakpoint after removing probe from script-1:10:0' )
938+ assert . strictEqual ( err . cause , cause )
939+ return true
940+ }
941+ )
942+ } )
795943 } )
796944
797945 it ( 'should throw error if debugger not started' , async function ( ) {
0 commit comments