Skip to content

Commit d2d9498

Browse files
committed
debugSession: more precise errors
1 parent 35dfc70 commit d2d9498

2 files changed

Lines changed: 36 additions & 36 deletions

File tree

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { URI } from 'vs/base/common/uri';
77
import * as resources from 'vs/base/common/resources';
8-
import * as nls from 'vs/nls';
98
import * as platform from 'vs/base/common/platform';
109
import severity from 'vs/base/common/severity';
1110
import { Event, Emitter } from 'vs/base/common/event';
@@ -34,6 +33,7 @@ import { CancellationTokenSource, CancellationToken } from 'vs/base/common/cance
3433
import { distinct } from 'vs/base/common/arrays';
3534
import { INotificationService } from 'vs/platform/notification/common/notification';
3635
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
36+
import { localize } from 'vs/nls';
3737

3838
export class DebugSession implements IDebugSession {
3939

@@ -232,7 +232,7 @@ export class DebugSession implements IDebugSession {
232232
*/
233233
async launchOrAttach(config: IConfig): Promise<void> {
234234
if (!this.raw) {
235-
throw new Error('no debug adapter');
235+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'launch or attach'));
236236
}
237237

238238
// __sessionID only used for EH debugging (but we add it always for now...)
@@ -250,7 +250,7 @@ export class DebugSession implements IDebugSession {
250250
*/
251251
async terminate(restart = false): Promise<void> {
252252
if (!this.raw) {
253-
throw new Error('no debug adapter');
253+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'terminate'));
254254
}
255255

256256
this.cancelAllRequests();
@@ -266,7 +266,7 @@ export class DebugSession implements IDebugSession {
266266
*/
267267
async disconnect(restart = false): Promise<void> {
268268
if (!this.raw) {
269-
throw new Error('no debug adapter');
269+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'disconnect'));
270270
}
271271

272272
this.cancelAllRequests();
@@ -278,7 +278,7 @@ export class DebugSession implements IDebugSession {
278278
*/
279279
async restart(): Promise<void> {
280280
if (!this.raw) {
281-
throw new Error('no debug adapter');
281+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'restart'));
282282
}
283283

284284
this.cancelAllRequests();
@@ -287,7 +287,7 @@ export class DebugSession implements IDebugSession {
287287

288288
async sendBreakpoints(modelUri: URI, breakpointsToSend: IBreakpoint[], sourceModified: boolean): Promise<void> {
289289
if (!this.raw) {
290-
throw new Error('no debug adapter');
290+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'breakpoints'));
291291
}
292292

293293
if (!this.raw.readyForBreakpoints) {
@@ -321,7 +321,7 @@ export class DebugSession implements IDebugSession {
321321

322322
async sendFunctionBreakpoints(fbpts: IFunctionBreakpoint[]): Promise<void> {
323323
if (!this.raw) {
324-
throw new Error('no debug adapter');
324+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'function breakpoints'));
325325
}
326326

327327
if (this.raw.readyForBreakpoints) {
@@ -338,7 +338,7 @@ export class DebugSession implements IDebugSession {
338338

339339
async sendExceptionBreakpoints(exbpts: IExceptionBreakpoint[]): Promise<void> {
340340
if (!this.raw) {
341-
throw new Error('no debug adapter');
341+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'exception breakpoints'));
342342
}
343343

344344
if (this.raw.readyForBreakpoints) {
@@ -348,10 +348,10 @@ export class DebugSession implements IDebugSession {
348348

349349
async dataBreakpointInfo(name: string, variablesReference?: number): Promise<{ dataId: string | null, description: string, canPersist?: boolean }> {
350350
if (!this.raw) {
351-
throw new Error('no debug adapter');
351+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'data breakpoints info'));
352352
}
353353
if (!this.raw.readyForBreakpoints) {
354-
throw new Error(nls.localize('sessionNotReadyForBreakpoints', "Session is not ready for breakpoints"));
354+
throw new Error(localize('sessionNotReadyForBreakpoints', "Session is not ready for breakpoints"));
355355
}
356356

357357
const response = await this.raw.dataBreakpointInfo({ name, variablesReference });
@@ -360,7 +360,7 @@ export class DebugSession implements IDebugSession {
360360

361361
async sendDataBreakpoints(dataBreakpoints: IDataBreakpoint[]): Promise<void> {
362362
if (!this.raw) {
363-
throw new Error('no debug adapter');
363+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'data breakpoints'));
364364
}
365365

366366
if (this.raw.readyForBreakpoints) {
@@ -377,7 +377,7 @@ export class DebugSession implements IDebugSession {
377377

378378
async breakpointsLocations(uri: URI, lineNumber: number): Promise<IPosition[]> {
379379
if (!this.raw) {
380-
throw new Error('no debug adapter');
380+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'breakpoints locations'));
381381
}
382382

383383
const source = this.getRawSource(uri);
@@ -393,15 +393,15 @@ export class DebugSession implements IDebugSession {
393393

394394
customRequest(request: string, args: any): Promise<DebugProtocol.Response> {
395395
if (!this.raw) {
396-
throw new Error('no debug adapter');
396+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", request));
397397
}
398398

399399
return this.raw.custom(request, args);
400400
}
401401

402402
stackTrace(threadId: number, startFrame: number, levels: number): Promise<DebugProtocol.StackTraceResponse> {
403403
if (!this.raw) {
404-
throw new Error('no debug adapter');
404+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'stackTrace'));
405405
}
406406

407407
const token = this.getNewCancellationToken(threadId);
@@ -410,7 +410,7 @@ export class DebugSession implements IDebugSession {
410410

411411
async exceptionInfo(threadId: number): Promise<IExceptionInfo | undefined> {
412412
if (!this.raw) {
413-
throw new Error('no debug adapter');
413+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'exceptionInfo'));
414414
}
415415

416416
const response = await this.raw.exceptionInfo({ threadId });
@@ -428,7 +428,7 @@ export class DebugSession implements IDebugSession {
428428

429429
scopes(frameId: number, threadId: number): Promise<DebugProtocol.ScopesResponse> {
430430
if (!this.raw) {
431-
throw new Error('no debug adapter');
431+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'scopes'));
432432
}
433433

434434
const token = this.getNewCancellationToken(threadId);
@@ -437,7 +437,7 @@ export class DebugSession implements IDebugSession {
437437

438438
variables(variablesReference: number, threadId: number | undefined, filter: 'indexed' | 'named' | undefined, start: number | undefined, count: number | undefined): Promise<DebugProtocol.VariablesResponse> {
439439
if (!this.raw) {
440-
throw new Error('no debug adapter');
440+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'variables'));
441441
}
442442

443443
const token = threadId ? this.getNewCancellationToken(threadId) : undefined;
@@ -446,111 +446,111 @@ export class DebugSession implements IDebugSession {
446446

447447
evaluate(expression: string, frameId: number, context?: string): Promise<DebugProtocol.EvaluateResponse> {
448448
if (!this.raw) {
449-
throw new Error('no debug adapter');
449+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'evaluate'));
450450
}
451451

452452
return this.raw.evaluate({ expression, frameId, context });
453453
}
454454

455455
async restartFrame(frameId: number, threadId: number): Promise<void> {
456456
if (!this.raw) {
457-
throw new Error('no debug adapter');
457+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'restartFrame'));
458458
}
459459

460460
await this.raw.restartFrame({ frameId }, threadId);
461461
}
462462

463463
async next(threadId: number): Promise<void> {
464464
if (!this.raw) {
465-
throw new Error('no debug adapter');
465+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'next'));
466466
}
467467

468468
await this.raw.next({ threadId });
469469
}
470470

471471
async stepIn(threadId: number): Promise<void> {
472472
if (!this.raw) {
473-
throw new Error('no debug adapter');
473+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'stepIn'));
474474
}
475475

476476
await this.raw.stepIn({ threadId });
477477
}
478478

479479
async stepOut(threadId: number): Promise<void> {
480480
if (!this.raw) {
481-
throw new Error('no debug adapter');
481+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'stepOut'));
482482
}
483483

484484
await this.raw.stepOut({ threadId });
485485
}
486486

487487
async stepBack(threadId: number): Promise<void> {
488488
if (!this.raw) {
489-
throw new Error('no debug adapter');
489+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'stepBack'));
490490
}
491491

492492
await this.raw.stepBack({ threadId });
493493
}
494494

495495
async continue(threadId: number): Promise<void> {
496496
if (!this.raw) {
497-
throw new Error('no debug adapter');
497+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'continue'));
498498
}
499499

500500
await this.raw.continue({ threadId });
501501
}
502502

503503
async reverseContinue(threadId: number): Promise<void> {
504504
if (!this.raw) {
505-
throw new Error('no debug adapter');
505+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'reverse continue'));
506506
}
507507

508508
await this.raw.reverseContinue({ threadId });
509509
}
510510

511511
async pause(threadId: number): Promise<void> {
512512
if (!this.raw) {
513-
throw new Error('no debug adapter');
513+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'pause'));
514514
}
515515

516516
await this.raw.pause({ threadId });
517517
}
518518

519519
async terminateThreads(threadIds?: number[]): Promise<void> {
520520
if (!this.raw) {
521-
throw new Error('no debug adapter');
521+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'terminateThreads'));
522522
}
523523

524524
await this.raw.terminateThreads({ threadIds });
525525
}
526526

527527
setVariable(variablesReference: number, name: string, value: string): Promise<DebugProtocol.SetVariableResponse> {
528528
if (!this.raw) {
529-
throw new Error('no debug adapter');
529+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'setVariable'));
530530
}
531531

532532
return this.raw.setVariable({ variablesReference, name, value });
533533
}
534534

535535
gotoTargets(source: DebugProtocol.Source, line: number, column?: number): Promise<DebugProtocol.GotoTargetsResponse> {
536536
if (!this.raw) {
537-
throw new Error('no debug adapter');
537+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'gotoTargets'));
538538
}
539539

540540
return this.raw.gotoTargets({ source, line, column });
541541
}
542542

543543
goto(threadId: number, targetId: number): Promise<DebugProtocol.GotoResponse> {
544544
if (!this.raw) {
545-
throw new Error('no debug adapter');
545+
throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'goto'));
546546
}
547547

548548
return this.raw.goto({ threadId, targetId });
549549
}
550550

551551
loadSource(resource: URI): Promise<DebugProtocol.SourceResponse> {
552552
if (!this.raw) {
553-
return Promise.reject(new Error('no debug adapter'));
553+
return Promise.reject(new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'loadSource')));
554554
}
555555

556556
const source = this.getSourceForUri(resource);
@@ -568,7 +568,7 @@ export class DebugSession implements IDebugSession {
568568

569569
async getLoadedSources(): Promise<Source[]> {
570570
if (!this.raw) {
571-
return Promise.reject(new Error('no debug adapter'));
571+
return Promise.reject(new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'getLoadedSources')));
572572
}
573573

574574
const response = await this.raw.loadedSources({});
@@ -581,7 +581,7 @@ export class DebugSession implements IDebugSession {
581581

582582
async completions(frameId: number | undefined, text: string, position: Position, overwriteBefore: number, token: CancellationToken): Promise<DebugProtocol.CompletionsResponse> {
583583
if (!this.raw) {
584-
return Promise.reject(new Error('no debug adapter'));
584+
return Promise.reject(new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", 'completions')));
585585
}
586586

587587
return this.raw.completions({
@@ -700,7 +700,7 @@ export class DebugSession implements IDebugSession {
700700
}
701701

702702
this.rawListeners.push(this.raw.onDidInitialize(async () => {
703-
aria.status(nls.localize('debuggingStarted', "Debugging started."));
703+
aria.status(localize('debuggingStarted', "Debugging started."));
704704
const sendConfigurationDone = async () => {
705705
if (this.raw && this.raw.capabilities.supportsConfigurationDoneRequest) {
706706
try {
@@ -782,7 +782,7 @@ export class DebugSession implements IDebugSession {
782782
}));
783783

784784
this.rawListeners.push(this.raw.onDidTerminateDebugee(async event => {
785-
aria.status(nls.localize('debuggingStopped', "Debugging stopped."));
785+
aria.status(localize('debuggingStopped', "Debugging stopped."));
786786
if (event.body && event.body.restart) {
787787
await this.debugService.restartSession(this, event.body.restart);
788788
} else if (this.raw) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export class RawDebugSession implements IDisposable {
230230
*/
231231
async start(): Promise<void> {
232232
if (!this.debugAdapter) {
233-
return Promise.reject(new Error('no debug adapter'));
233+
return Promise.reject(new Error(nls.localize('noDebugAdapterStart', "No debug adapter, can not start debug session.")));
234234
}
235235

236236
await this.debugAdapter.startSession();

0 commit comments

Comments
 (0)