@@ -88,6 +88,7 @@ export class PythonDebugger extends DebugSession {
8888 }
8989 if ( this . pythonProcess ) {
9090 this . pythonProcess . Kill ( ) ;
91+ this . pythonProcess = null ;
9192 }
9293 }
9394 private InitializeEventHandlers ( ) {
@@ -183,12 +184,28 @@ export class PythonDebugger extends DebugSession {
183184 let that = this ;
184185
185186 this . startDebugServer ( ) . then ( dbgServer => {
186- return that . debugClient . LaunchApplicationToDebug ( dbgServer ) ;
187+ return that . debugClient . LaunchApplicationToDebug ( dbgServer , that . unhandledProcessError . bind ( that ) ) ;
187188 } ) . catch ( error => {
188189 this . sendEvent ( new OutputEvent ( error + "\n" , "stderr" ) ) ;
189- this . sendErrorResponse ( that . entryResponse , 2000 , error ) ;
190+ response . success = false ;
191+ let errorMsg = typeof error === "string" ? error : ( ( error . message && error . message . length > 0 ) ? error . message : error + '' ) ;
192+ if ( ( < any > error ) . code === 'ENOENT' || ( < any > error ) . code === 127 ) {
193+ errorMsg = `Failed to launch the Python Process, please validate the path '${ this . launchArgs . pythonPath } '` ;
194+ }
195+ this . sendErrorResponse ( response , 200 , errorMsg ) ;
190196 } ) ;
191197 }
198+ protected unhandledProcessError ( error : any ) {
199+ if ( ! error ) { return ; }
200+ let errorMsg = typeof error === "string" ? error : ( ( error . message && error . message . length > 0 ) ? error . message : "" ) ;
201+ if ( ( < any > error ) . code === 'ENOENT' || ( < any > error ) . code === 127 ) {
202+ errorMsg = `Failed to launch the Python Process, please validate the path '${ this . launchArgs . pythonPath } '` ;
203+ }
204+ if ( errorMsg . length > 0 ) {
205+ this . sendEvent ( new OutputEvent ( errorMsg + "\n" , "stderr" ) ) ;
206+ }
207+ this . sendEvent ( new TerminatedEvent ( ) ) ;
208+ }
192209 protected attachRequest ( response : DebugProtocol . AttachResponse , args : AttachRequestArguments ) {
193210 this . sendEvent ( new TelemetryEvent ( telemetryContracts . Debugger . Attach ) ) ;
194211 this . attachArgs = args ;
@@ -199,7 +216,7 @@ export class PythonDebugger extends DebugSession {
199216 this . canStartDebugger ( ) . then ( ( ) => {
200217 return this . startDebugServer ( ) ;
201218 } ) . then ( dbgServer => {
202- return that . debugClient . LaunchApplicationToDebug ( dbgServer ) ;
219+ return that . debugClient . LaunchApplicationToDebug ( dbgServer , ( ) => { } ) ;
203220 } ) . catch ( error => {
204221 this . sendEvent ( new OutputEvent ( error + "\n" , "stderr" ) ) ;
205222 this . sendErrorResponse ( that . entryResponse , 2000 , error ) ;
0 commit comments