提交 62f00c94 编写于 作者: I isidor

debug: null guards when getting response from debug adapter

fixes #12123
fixes #12120
上级 8a3d5b2e
......@@ -132,6 +132,10 @@ export class Thread implements debug.IThread {
private getCallStackImpl(debugService: debug.IDebugService, startFrame: number): TPromise<debug.IStackFrame[]> {
let session = debugService.getActiveSession();
return session.stackTrace({ threadId: this.threadId, startFrame, levels: 20 }).then(response => {
if (!response || !response.body) {
return [];
}
this.stoppedDetails.totalFrames = response.body.totalFrames;
return response.body.stackFrames.map((rsf, level) => {
if (!rsf) {
......@@ -295,9 +299,9 @@ export abstract class ExpressionContainer implements debug.IExpressionContainer
count,
filter
}).then(response => {
return arrays.distinct(response.body.variables.filter(v => !!v), v => v.name).map(
return response && response.body && response.body.variables ? arrays.distinct(response.body.variables.filter(v => !!v), v => v.name).map(
v => new Variable(this, v.variablesReference, v.name, v.value, v.namedVariables, v.indexedVariables, v.type)
);
) : [];
}, (e: Error) => [new Variable(this, 0, null, e.message, 0, 0, null, false)]);
}
......@@ -384,7 +388,8 @@ export class StackFrame implements debug.IStackFrame {
public getScopes(debugService: debug.IDebugService): TPromise<debug.IScope[]> {
if (!this.scopes) {
this.scopes = debugService.getActiveSession().scopes({ frameId: this.frameId }).then(response => {
return response.body.scopes.map(rs => new Scope(this.threadId, rs.name, rs.variablesReference, rs.expensive, rs.namedVariables, rs.indexedVariables));
return response && response.body && response.body.scopes ?
response.body.scopes.map(rs => new Scope(this.threadId, rs.name, rs.variablesReference, rs.expensive, rs.namedVariables, rs.indexedVariables)) : [];
}, err => []);
}
......
......@@ -346,7 +346,9 @@ export class DebugService implements debug.IDebugService {
private getThreadData(): TPromise<void> {
return this.session.threads().then(response => {
response.body.threads.forEach(thread => this.model.rawUpdate({ threadId: thread.id, thread }));
if (response && response.body && response.body.threads) {
response.body.threads.forEach(thread => this.model.rawUpdate({ threadId: thread.id, thread }));
}
});
}
......@@ -508,7 +510,9 @@ export class DebugService implements debug.IDebugService {
value,
variablesReference: (<model.Variable>variable).parent.reference
}).then(response => {
variable.value = response.body.value;
if (response && response.body) {
variable.value = response.body.value;
}
// Evaluate all watch expressions again since changing variable value might have changed some #8118.
return this.setFocusedStackFrameAndEvaluate(this.viewModel.getFocusedStackFrame());
}, err => {
......@@ -838,8 +842,9 @@ export class DebugService implements debug.IDebugService {
// internal module
if (source.reference !== 0 && this.session && source.available) {
return this.session.source({ sourceReference: source.reference }).then(response => {
const mime = response.body.mimeType ? response.body.mimeType : guessMimeTypes(source.name)[0];
return this.getDebugStringEditorInput(source, response.body.content, mime);
const mime = response && response.body && response.body.mimeType ? response.body.mimeType : guessMimeTypes(source.name)[0];
const inputValue = response && response.body ? response.body.content : '';
return this.getDebugStringEditorInput(source, inputValue, mime);
}, (err: DebugProtocol.ErrorResponse) => {
// Display the error from debug adapter using a temporary editor #8836
return this.getDebugErrorEditorInput(source, err.message);
......@@ -924,7 +929,7 @@ export class DebugService implements debug.IDebugService {
}
return this.session.continue({ threadId }).then(response => {
const allThreadsContinued = response.body ? response.body.allThreadsContinued !== false : true;
const allThreadsContinued = response && response.body ? response.body.allThreadsContinued !== false : true;
this.lazyTransitionToRunningState(allThreadsContinued ? undefined : threadId);
});
}
......@@ -957,11 +962,11 @@ export class DebugService implements debug.IDebugService {
column: position.column,
line: position.lineNumber
}).then(response => {
return !response ? [] : response.body.targets.map(item => ({
return response && response.body && response.body.targets ? response.body.targets.map(item => ({
label: item.label,
insertText: item.text || item.label,
type: item.type
}));
})) : [];
}, err => []);
}
......@@ -1041,6 +1046,10 @@ export class DebugService implements debug.IDebugService {
breakpoints: breakpointsToSend.map(bp => ({ line: bp.desiredLineNumber, condition: bp.condition })),
sourceModified
}).then(response => {
if (!response || !response.body) {
return;
}
const data: { [id: string]: { line?: number, verified: boolean } } = {};
for (let i = 0; i < breakpointsToSend.length; i++) {
data[breakpointsToSend[i].getId()] = response.body.breakpoints[i];
......@@ -1057,6 +1066,10 @@ export class DebugService implements debug.IDebugService {
const breakpointsToSend = this.model.getFunctionBreakpoints().filter(fbp => fbp.enabled && this.model.areBreakpointsActivated());
return this.session.setFunctionBreakpoints({ breakpoints: breakpointsToSend }).then(response => {
if (!response || !response.body) {
return;
}
const data: { [id: string]: { name?: string, verified?: boolean } } = {};
for (let i = 0; i < breakpointsToSend.length; i++) {
data[breakpointsToSend[i].getId()] = response.body.breakpoints[i];
......
......@@ -155,8 +155,9 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes
protected send(command: string, args: any, cancelOnDisconnect = true): TPromise<DebugProtocol.Response> {
return this.initServer().then(() => {
const promise = super.send(command, args).then(response => response, (errorResponse: DebugProtocol.ErrorResponse) => {
const error = errorResponse.body ? errorResponse.body.error : null;
const telemetryMessage = error ? debug.formatPII(error.format, true, error.variables) : errorResponse.message;
const error = errorResponse && errorResponse.body ? errorResponse.body.error : null;
const errorMessage = errorResponse ? errorResponse.message : '';
const telemetryMessage = error ? debug.formatPII(error.format, true, error.variables) : errorMessage;
if (error && error.sendTelemetry) {
this.telemetryService.publicLog('debugProtocolErrorResponse', { error: telemetryMessage });
if (this.customTelemetryService) {
......@@ -168,7 +169,7 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes
return TPromise.as(null);
}
const userMessage = error ? debug.formatPII(error.format, false, error.variables) : errorResponse.message;
const userMessage = error ? debug.formatPII(error.format, false, error.variables) : errorMessage;
if (error && error.url) {
const label = error.urlLabel ? error.urlLabel : nls.localize('moreInfo', "More Info");
return TPromise.wrapError(errors.create(userMessage, { actions: [CloseAction, new Action('debug.moreInfo', label, null, true, () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册