Skip to content

Commit

Permalink
Refactored step operations to cover all error scenarios.
Browse files Browse the repository at this point in the history
Handle them, where possible, with sendErrorResponse and OutputEvent in other cases.
  • Loading branch information
zobo committed Jan 26, 2021
1 parent 37124d4 commit 0b65485
Showing 1 changed file with 50 additions and 28 deletions.
78 changes: 50 additions & 28 deletions src/phpDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -894,84 +894,106 @@ 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))
}
response.body = {
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) {
Expand Down

0 comments on commit 0b65485

Please sign in to comment.