diff --git a/src/adapter/stackTrace.ts b/src/adapter/stackTrace.ts index d705d51f4..919531453 100644 --- a/src/adapter/stackTrace.ts +++ b/src/adapter/stackTrace.ts @@ -10,6 +10,7 @@ import { IPreferredUiLocation } from './sources'; import { RawLocation, Thread } from './threads'; import { IExtraProperty, IScopeRef } from './variables'; import { LogPointCompiler } from './breakpoints/conditions/logPoint'; +import { asyncScopesNotAvailable, ProtocolError } from '../dap/errors'; const localize = nls.loadMessageBundle(); @@ -184,7 +185,9 @@ export class StackFrame { } async scopes(): Promise { - if (!this._scope) return { scopes: [] }; + if (!this._scope) { + throw new ProtocolError(asyncScopesNotAvailable()); + } const scopes: Dap.Scope[] = []; for (let scopeNumber = 0; scopeNumber < this._scope.chain.length; scopeNumber++) { diff --git a/src/dap/connection.ts b/src/dap/connection.ts index 8ed14cfbc..f438bc09f 100644 --- a/src/dap/connection.ts +++ b/src/dap/connection.ts @@ -183,7 +183,6 @@ export default class Connection { Number(process.hrtime.bigint() - receivedTime) / 1e6, ); } catch (e) { - console.error(e); const format = isExternalError(e) ? e.message : `Error processing ${msg.command}: ${e.stack || e.message}`; @@ -195,6 +194,7 @@ export default class Connection { body: { error: e.cause }, }); } else { + console.error(e); this._send({ ...response, success: false, diff --git a/src/dap/errors.ts b/src/dap/errors.ts index ea97f62a5..c8a21ba06 100644 --- a/src/dap/errors.ts +++ b/src/dap/errors.ts @@ -19,6 +19,7 @@ export const enum ErrorCodes { InvalidHitCondition, InvalidLogPointBreakpointSyntax, BrowserNotFound, + AsyncScopesNotAvailable, } export function reportToConsole(dap: Dap.Api, error: string) { @@ -28,11 +29,11 @@ export function reportToConsole(dap: Dap.Api, error: string) { }); } -export function createSilentError(text: string): Dap.Error { +export function createSilentError(text: string, code = ErrorCodes.SilentError): Dap.Error { return { __errorMarker: true, error: { - id: ErrorCodes.SilentError, + id: code, format: text, showUser: false, }, @@ -147,6 +148,15 @@ export const browserNotFound = ( export const invalidLogPointSyntax = (error: string) => createUserError(error, ErrorCodes.InvalidLogPointBreakpointSyntax); +export const asyncScopesNotAvailable = () => + createSilentError( + localize( + 'asyncScopesNotAvailable', + 'Variables not available in async stacks', + ErrorCodes.AsyncScopesNotAvailable, + ), + ); + export class ProtocolError extends Error { public readonly cause: Dap.Message; diff --git a/src/test/logger.ts b/src/test/logger.ts index 539e7eb10..6beab6805 100644 --- a/src/test/logger.ts +++ b/src/test/logger.ts @@ -161,23 +161,27 @@ export class Logger { ); if (!withScopes) continue; const scopes = await this._dap.scopes({ frameId: frame.id }); - for (let i = 0; i < scopes.scopes.length; i++) { - const scope = scopes.scopes[i]; - if (scope.expensive) { - this._log(` scope #${i}: ${scope.name} [expensive]`); - continue; + if (typeof scopes === 'string') { + this._log(` scope error: ${scopes}`); + } else { + for (let i = 0; i < scopes.scopes.length; i++) { + const scope = scopes.scopes[i]; + if (scope.expensive) { + this._log(` scope #${i}: ${scope.name} [expensive]`); + continue; + } + await this.logVariable( + { + name: 'scope #' + i, + value: scope.name, + variablesReference: scope.variablesReference, + namedVariables: scope.namedVariables, + indexedVariables: scope.indexedVariables, + }, + {}, + ' ', + ); } - await this.logVariable( - { - name: 'scope #' + i, - value: scope.name, - variablesReference: scope.variablesReference, - namedVariables: scope.namedVariables, - indexedVariables: scope.indexedVariables, - }, - {}, - ' ', - ); } } diff --git a/src/test/stacks/stacks-async.txt b/src/test/stacks/stacks-async.txt index 64d212c61..a29131841 100644 --- a/src/test/stacks/stacks-async.txt +++ b/src/test/stacks/stacks-async.txt @@ -13,8 +13,12 @@ bar @ /VM:13:15 ----async function---- @ /VM:8:11 + scope error: Variables not available in async stacks ----setTimeout---- foo @ /VM:7:9 + scope error: Variables not available in async stacks bar @ /VM:13:15 + scope error: Variables not available in async stacks ----async function---- @ /VM:15:7 + scope error: Variables not available in async stacks diff --git a/src/test/stacks/stacks-cross-target.txt b/src/test/stacks/stacks-cross-target.txt index adbd397e4..3c91a0ede 100644 --- a/src/test/stacks/stacks-cross-target.txt +++ b/src/test/stacks/stacks-cross-target.txt @@ -7,5 +7,7 @@ ----postMessage---- @ ${workspaceFolder}/web/worker.js:6:5 + scope error: Variables not available in async stacks ----Worker.postMessage---- @ /VM:1:10 + scope error: Variables not available in async stacks