Skip to content

Commit 9a2a941

Browse files
committed
debug: return result of a msg to debug adapter can be undefined
1 parent 371f630 commit 9a2a941

File tree

6 files changed

+81
-71
lines changed

6 files changed

+81
-71
lines changed

src/vs/workbench/contrib/debug/browser/debugActions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@ export class CopyValueAction extends Action {
408408

409409
try {
410410
const evaluation = await session.evaluate(toEvaluate, stackFrame.frameId, context);
411-
this.clipboardService.writeText(evaluation.body.result);
411+
if (evaluation) {
412+
this.clipboardService.writeText(evaluation.body.result);
413+
}
412414
} catch (e) {
413415
this.clipboardService.writeText(typeof this.value === 'string' ? this.value : this.value.value);
414416
}

src/vs/workbench/contrib/debug/browser/debugCommands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ export function registerCommands(): void {
167167
const source = stackFrame.thread.session.getSourceForUri(resource);
168168
if (source) {
169169
const response = await stackFrame.thread.session.gotoTargets(source.raw, position.lineNumber, position.column);
170-
const targets = response.body.targets;
171-
if (targets.length) {
170+
const targets = response?.body.targets;
171+
if (targets && targets.length) {
172172
let id = targets[0].id;
173173
if (targets.length > 1) {
174174
const picks = targets.map(t => ({ label: t.label, _id: t.id }));

src/vs/workbench/contrib/debug/browser/debugEditorActions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ class StepIntoTargetsAction extends EditorAction {
277277

278278
if (session && frame && editor.hasModel() && editor.getModel().uri.toString() === frame.source.uri.toString()) {
279279
const targets = await session.stepInTargets(frame.frameId);
280+
if (!targets) {
281+
return;
282+
}
283+
280284
editor.revealLineInCenterIfOutsideViewport(frame.range.startLineNumber);
281285
const cursorCoords = editor.getScrolledVisiblePosition({ lineNumber: frame.range.startLineNumber, column: frame.range.startColumn });
282286
const editorCoords = getDomNodePagePosition(editor.getDomNode());

src/vs/workbench/contrib/debug/browser/debugSession.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ export class DebugSession implements IDebugSession {
404404
}
405405

406406
const response = await this.raw.dataBreakpointInfo({ name, variablesReference });
407-
return response.body;
407+
return response?.body;
408408
}
409409

410410
async sendDataBreakpoints(dataBreakpoints: IDataBreakpoint[]): Promise<void> {
@@ -431,7 +431,7 @@ export class DebugSession implements IDebugSession {
431431

432432
const source = this.getRawSource(uri);
433433
const response = await this.raw.breakpointLocations({ source, line: lineNumber });
434-
if (!response.body || !response.body.breakpoints) {
434+
if (!response || !response.body || !response.body.breakpoints) {
435435
return [];
436436
}
437437

@@ -444,15 +444,15 @@ export class DebugSession implements IDebugSession {
444444
return this.model.getDebugProtocolBreakpoint(breakpointId, this.getId());
445445
}
446446

447-
customRequest(request: string, args: any): Promise<DebugProtocol.Response> {
447+
customRequest(request: string, args: any): Promise<DebugProtocol.Response | undefined> {
448448
if (!this.raw) {
449449
throw new Error(localize('noDebugAdapter', "No debugger available, can not send '{0}'", request));
450450
}
451451

452452
return this.raw.custom(request, args);
453453
}
454454

455-
stackTrace(threadId: number, startFrame: number, levels: number, token: CancellationToken): Promise<DebugProtocol.StackTraceResponse> {
455+
stackTrace(threadId: number, startFrame: number, levels: number, token: CancellationToken): Promise<DebugProtocol.StackTraceResponse | undefined> {
456456
if (!this.raw) {
457457
throw new Error(localize('noDebugAdapter', "No debugger available, can not send '{0}'", 'stackTrace'));
458458
}
@@ -479,7 +479,7 @@ export class DebugSession implements IDebugSession {
479479
return undefined;
480480
}
481481

482-
scopes(frameId: number, threadId: number): Promise<DebugProtocol.ScopesResponse> {
482+
scopes(frameId: number, threadId: number): Promise<DebugProtocol.ScopesResponse | undefined> {
483483
if (!this.raw) {
484484
throw new Error(localize('noDebugAdapter', "No debugger available, can not send '{0}'", 'scopes'));
485485
}
@@ -488,7 +488,7 @@ export class DebugSession implements IDebugSession {
488488
return this.raw.scopes({ frameId }, token);
489489
}
490490

491-
variables(variablesReference: number, threadId: number | undefined, filter: 'indexed' | 'named' | undefined, start: number | undefined, count: number | undefined): Promise<DebugProtocol.VariablesResponse> {
491+
variables(variablesReference: number, threadId: number | undefined, filter: 'indexed' | 'named' | undefined, start: number | undefined, count: number | undefined): Promise<DebugProtocol.VariablesResponse | undefined> {
492492
if (!this.raw) {
493493
throw new Error(localize('noDebugAdapter', "No debugger available, can not send '{0}'", 'variables'));
494494
}
@@ -497,7 +497,7 @@ export class DebugSession implements IDebugSession {
497497
return this.raw.variables({ variablesReference, filter, start, count }, token);
498498
}
499499

500-
evaluate(expression: string, frameId: number, context?: string): Promise<DebugProtocol.EvaluateResponse> {
500+
evaluate(expression: string, frameId: number, context?: string): Promise<DebugProtocol.EvaluateResponse | undefined> {
501501
if (!this.raw) {
502502
throw new Error(localize('noDebugAdapter', "No debugger available, can not send '{0}'", 'evaluate'));
503503
}
@@ -577,31 +577,31 @@ export class DebugSession implements IDebugSession {
577577
await this.raw.terminateThreads({ threadIds });
578578
}
579579

580-
setVariable(variablesReference: number, name: string, value: string): Promise<DebugProtocol.SetVariableResponse> {
580+
setVariable(variablesReference: number, name: string, value: string): Promise<DebugProtocol.SetVariableResponse | undefined> {
581581
if (!this.raw) {
582582
throw new Error(localize('noDebugAdapter', "No debugger available, can not send '{0}'", 'setVariable'));
583583
}
584584

585585
return this.raw.setVariable({ variablesReference, name, value });
586586
}
587587

588-
gotoTargets(source: DebugProtocol.Source, line: number, column?: number): Promise<DebugProtocol.GotoTargetsResponse> {
588+
gotoTargets(source: DebugProtocol.Source, line: number, column?: number): Promise<DebugProtocol.GotoTargetsResponse | undefined> {
589589
if (!this.raw) {
590590
throw new Error(localize('noDebugAdapter', "No debugger available, can not send '{0}'", 'gotoTargets'));
591591
}
592592

593593
return this.raw.gotoTargets({ source, line, column });
594594
}
595595

596-
goto(threadId: number, targetId: number): Promise<DebugProtocol.GotoResponse> {
596+
goto(threadId: number, targetId: number): Promise<DebugProtocol.GotoResponse | undefined> {
597597
if (!this.raw) {
598598
throw new Error(localize('noDebugAdapter', "No debugger available, can not send '{0}'", 'goto'));
599599
}
600600

601601
return this.raw.goto({ threadId, targetId });
602602
}
603603

604-
loadSource(resource: URI): Promise<DebugProtocol.SourceResponse> {
604+
loadSource(resource: URI): Promise<DebugProtocol.SourceResponse | undefined> {
605605
if (!this.raw) {
606606
return Promise.reject(new Error(localize('noDebugAdapter', "No debugger available, can not send '{0}'", 'loadSource')));
607607
}
@@ -632,7 +632,7 @@ export class DebugSession implements IDebugSession {
632632
}
633633
}
634634

635-
async completions(frameId: number | undefined, threadId: number, text: string, position: Position, overwriteBefore: number, token: CancellationToken): Promise<DebugProtocol.CompletionsResponse> {
635+
async completions(frameId: number | undefined, threadId: number, text: string, position: Position, overwriteBefore: number, token: CancellationToken): Promise<DebugProtocol.CompletionsResponse | undefined> {
636636
if (!this.raw) {
637637
return Promise.reject(new Error(localize('noDebugAdapter', "No debugger available, can not send '{0}'", 'completions')));
638638
}
@@ -646,16 +646,16 @@ export class DebugSession implements IDebugSession {
646646
}, sessionCancelationToken);
647647
}
648648

649-
async stepInTargets(frameId: number): Promise<{ id: number, label: string }[]> {
649+
async stepInTargets(frameId: number): Promise<{ id: number, label: string }[] | undefined> {
650650
if (!this.raw) {
651651
return Promise.reject(new Error(localize('noDebugAdapter', "No debugger available, can not send '{0}'", 'stepInTargets')));
652652
}
653653

654654
const response = await this.raw.stepInTargets({ frameId });
655-
return response.body.targets;
655+
return response?.body.targets;
656656
}
657657

658-
async cancel(progressId: string): Promise<DebugProtocol.CancelResponse> {
658+
async cancel(progressId: string): Promise<DebugProtocol.CancelResponse | undefined> {
659659
if (!this.raw) {
660660
return Promise.reject(new Error(localize('noDebugAdapter', "No debugger available, can not send '{0}'", 'cancel')));
661661
}

0 commit comments

Comments
 (0)