From 0b65485c3dc0b06f7affab1b11f6ac5f478b71fc Mon Sep 17 00:00:00 2001 From: Damjan Cvetko Date: Wed, 27 Jan 2021 00:00:46 +0100 Subject: [PATCH] Refactored step operations to cover all error scenarios. Handle them, where possible, with sendErrorResponse and OutputEvent in other cases. --- src/phpDebug.ts | 78 +++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/src/phpDebug.ts b/src/phpDebug.ts index bb9db95c..3f22cbee 100644 --- a/src/phpDebug.ts +++ b/src/phpDebug.ts @@ -894,9 +894,9 @@ class PhpDebugSession extends vscode.DebugSession { response: VSCodeDebugProtocol.ContinueResponse, args: VSCodeDebugProtocol.ContinueArguments ) { - let xdebugResponse: xdebug.StatusResponse | undefined + let connection: xdebug.Connection | undefined try { - const connection = this._connections.get(args.threadId) + connection = this._connections.get(args.threadId) if (!connection) { return this.sendErrorResponse(response, new Error('Unknown thread ID ' + args.threadId)) } @@ -904,74 +904,96 @@ class PhpDebugSession extends vscode.DebugSession { allThreadsContinued: false, } this.sendResponse(response) - xdebugResponse = await connection.sendRunCommand() } catch (error) { - if (xdebugResponse) { - this._checkStatus(xdebugResponse) - } + this.sendErrorResponse(response, error) return } - this._checkStatus(xdebugResponse) + try { + const xdebugResponse = await connection.sendRunCommand() + this._checkStatus(xdebugResponse) + } catch (error) { + this.sendEvent( + new vscode.OutputEvent( + 'continueRequest thread ID ' + args.threadId + ' error: ' + error.message + '\n' + ), + true + ) + } } protected async nextRequest(response: VSCodeDebugProtocol.NextResponse, args: VSCodeDebugProtocol.NextArguments) { - let xdebugResponse: xdebug.StatusResponse | undefined + let connection: xdebug.Connection | undefined try { - const connection = this._connections.get(args.threadId) + connection = this._connections.get(args.threadId) if (!connection) { return this.sendErrorResponse(response, new Error('Unknown thread ID ' + args.threadId)) } this.sendResponse(response) - xdebugResponse = await connection.sendStepOverCommand() } catch (error) { - if (xdebugResponse) { - this._checkStatus(xdebugResponse) - } + this.sendErrorResponse(response, error) return } - this._checkStatus(xdebugResponse) + try { + const xdebugResponse = await connection.sendStepOverCommand() + this._checkStatus(xdebugResponse) + } catch (error) { + this.sendEvent( + new vscode.OutputEvent('nextRequest thread ID ' + args.threadId + ' error: ' + error.message + '\n'), + true + ) + } } protected async stepInRequest( response: VSCodeDebugProtocol.StepInResponse, args: VSCodeDebugProtocol.StepInArguments ) { - let xdebugResponse: xdebug.StatusResponse | undefined + let connection: xdebug.Connection | undefined try { - const connection = this._connections.get(args.threadId) + connection = this._connections.get(args.threadId) if (!connection) { return this.sendErrorResponse(response, new Error('Unknown thread ID ' + args.threadId)) } this.sendResponse(response) - xdebugResponse = await connection.sendStepIntoCommand() } catch (error) { - if (xdebugResponse) { - this._checkStatus(xdebugResponse) - } + this.sendErrorResponse(response, error) return } - this._checkStatus(xdebugResponse) + try { + const xdebugResponse = await connection.sendStepIntoCommand() + this._checkStatus(xdebugResponse) + } catch (error) { + this.sendEvent( + new vscode.OutputEvent('stepInRequest thread ID ' + args.threadId + ' error: ' + error.message + '\n'), + true + ) + } } protected async stepOutRequest( response: VSCodeDebugProtocol.StepOutResponse, args: VSCodeDebugProtocol.StepOutArguments ) { - let xdebugResponse: xdebug.StatusResponse | undefined + let connection: xdebug.Connection | undefined try { - const connection = this._connections.get(args.threadId) + connection = this._connections.get(args.threadId) if (!connection) { return this.sendErrorResponse(response, new Error('Unknown thread ID ' + args.threadId)) } this.sendResponse(response) - xdebugResponse = await connection.sendStepOutCommand() } catch (error) { - if (xdebugResponse) { - this._checkStatus(xdebugResponse) - } + this.sendErrorResponse(response, error) return } - this._checkStatus(xdebugResponse) + try { + const xdebugResponse = await connection.sendStepOutCommand() + this._checkStatus(xdebugResponse) + } catch (error) { + this.sendEvent( + new vscode.OutputEvent('stepOutRequest thread ID ' + args.threadId + ' error: ' + error.message + '\n'), + true + ) + } } protected pauseRequest(response: VSCodeDebugProtocol.PauseResponse, args: VSCodeDebugProtocol.PauseArguments) {