2121import { ServiceObject } from '@google-cloud/common' ;
2222import * as assert from 'assert' ;
2323import * as qs from 'querystring' ;
24- import * as request from 'request' ; // Only for type declarations.
24+ import * as request from 'request' ; // Only for type declarations.
2525
2626import { URL } from 'url' ;
2727
@@ -33,7 +33,7 @@ import * as stackdriver from '../types/stackdriver';
3333const API = 'https://clouddebugger.googleapis.com/v2/controller' ;
3434
3535export class Controller extends ServiceObject {
36- private nextWaitToken : string | null ;
36+ private nextWaitToken : string | null ;
3737
3838 apiUrl : string ;
3939
@@ -60,21 +60,28 @@ export class Controller extends ServiceObject {
6060 * @param {!function(?Error,Object=) } callback
6161 * @private
6262 */
63- register ( debuggee : Debuggee , callback : ( err : Error | null , result ?: {
64- debuggee : Debuggee
65- } ) => void ) : void {
63+ register (
64+ debuggee : Debuggee ,
65+ callback : (
66+ err : Error | null ,
67+ result ?: {
68+ debuggee : Debuggee ;
69+ }
70+ ) => void
71+ ) : void {
6672 const options = {
6773 uri : this . apiUrl + '/debuggees/register' ,
6874 method : 'POST' ,
6975 json : true ,
70- body : { debuggee}
76+ body : { debuggee} ,
7177 } ;
7278 this . request ( options , ( err , body : { debuggee : Debuggee } , response ) => {
7379 if ( err ) {
7480 callback ( err ) ;
7581 } else if ( response ! . statusCode !== 200 ) {
76- callback ( new Error (
77- 'unable to register, statusCode ' + response ! . statusCode ) ) ;
82+ callback (
83+ new Error ( 'unable to register, statusCode ' + response ! . statusCode )
84+ ) ;
7885 } else if ( ! body . debuggee ) {
7986 callback ( new Error ( 'invalid response body from server' ) ) ;
8087 } else {
@@ -84,49 +91,59 @@ export class Controller extends ServiceObject {
8491 } ) ;
8592 }
8693
87-
8894 /**
8995 * Fetch the list of breakpoints from the server. Assumes we have registered.
9096 * @param {!function(?Error,Object=,Object=) } callback accepting (err, response,
9197 * body)
9298 */
9399 listBreakpoints (
94- debuggee : Debuggee ,
95- callback :
96- ( err : Error | null , response ?: request . Response ,
97- body ?: stackdriver . ListBreakpointsResponse ) => void ) : void {
100+ debuggee : Debuggee ,
101+ callback : (
102+ err : Error | null ,
103+ response ?: request . Response ,
104+ body ?: stackdriver . ListBreakpointsResponse
105+ ) => void
106+ ) : void {
98107 const that = this ;
99108 assert ( debuggee . id , 'should have a registered debuggee' ) ;
100109 const query : stackdriver . ListBreakpointsQuery = { successOnTimeout : true } ;
101110 if ( that . nextWaitToken ) {
102111 query . waitToken = that . nextWaitToken ;
103112 }
104113
105- const uri = this . apiUrl + '/debuggees/' + encodeURIComponent ( debuggee . id ) +
106- '/breakpoints?' + qs . stringify ( query ) ;
114+ const uri =
115+ this . apiUrl +
116+ '/debuggees/' +
117+ encodeURIComponent ( debuggee . id ) +
118+ '/breakpoints?' +
119+ qs . stringify ( query ) ;
107120 that . request (
108- { uri, json : true } ,
109- ( err , body : stackdriver . ListBreakpointsResponse , response ) => {
110- if ( ! response ) {
111- callback (
112- err || new Error ( 'unknown error - request response missing' ) ) ;
113- return ;
114- } else if ( response . statusCode === 404 ) {
115- // The v2 API returns 404 (google.rpc.Code.NOT_FOUND) when the agent
116- // registration expires. We should re-register.
117- callback ( null , response ) ;
118- return ;
119- } else if ( response . statusCode !== 200 ) {
120- callback ( new Error (
121- 'unable to list breakpoints, status code ' +
122- response . statusCode ) ) ;
123- return ;
124- } else {
125- body = body || { } ;
126- that . nextWaitToken = body . nextWaitToken ;
127- callback ( null , response , body ) ;
128- }
129- } ) ;
121+ { uri, json : true } ,
122+ ( err , body : stackdriver . ListBreakpointsResponse , response ) => {
123+ if ( ! response ) {
124+ callback (
125+ err || new Error ( 'unknown error - request response missing' )
126+ ) ;
127+ return ;
128+ } else if ( response . statusCode === 404 ) {
129+ // The v2 API returns 404 (google.rpc.Code.NOT_FOUND) when the agent
130+ // registration expires. We should re-register.
131+ callback ( null , response ) ;
132+ return ;
133+ } else if ( response . statusCode !== 200 ) {
134+ callback (
135+ new Error (
136+ 'unable to list breakpoints, status code ' + response . statusCode
137+ )
138+ ) ;
139+ return ;
140+ } else {
141+ body = body || { } ;
142+ that . nextWaitToken = body . nextWaitToken ;
143+ callback ( null , response , body ) ;
144+ }
145+ }
146+ ) ;
130147 }
131148
132149 /**
@@ -136,19 +153,25 @@ export class Controller extends ServiceObject {
136153 * @param {!Function } callback accepting (err, body)
137154 */
138155 updateBreakpoint (
139- debuggee : Debuggee , breakpoint : stackdriver . Breakpoint ,
140- callback : ( err ?: Error , body ?: { } ) => void ) : void {
156+ debuggee : Debuggee ,
157+ breakpoint : stackdriver . Breakpoint ,
158+ callback : ( err ?: Error , body ?: { } ) => void
159+ ) : void {
141160 assert ( debuggee . id , 'should have a registered debuggee' ) ;
142161
143162 breakpoint . action = 'CAPTURE' ;
144163 breakpoint . isFinalState = true ;
145164 const options = {
146- uri : this . apiUrl + '/debuggees/' + encodeURIComponent ( debuggee . id ) +
147- // TODO: Address the case where `breakpoint.id` is `undefined`.
148- '/breakpoints/' + encodeURIComponent ( breakpoint . id as string ) ,
165+ uri :
166+ this . apiUrl +
167+ '/debuggees/' +
168+ encodeURIComponent ( debuggee . id ) +
169+ // TODO: Address the case where `breakpoint.id` is `undefined`.
170+ '/breakpoints/' +
171+ encodeURIComponent ( breakpoint . id as string ) ,
149172 json : true ,
150173 method : 'PUT' ,
151- body : { debuggeeId : debuggee . id , breakpoint}
174+ body : { debuggeeId : debuggee . id , breakpoint} ,
152175 } ;
153176
154177 // We need to have a try/catch here because a JSON.stringify will be done
0 commit comments