Skip to content

Commit 27cc5c9

Browse files
author
Anna Gringauze
authored
Cleanup creation of ChromeDebugException (#1690)
* Migrate debugging/inspector.dart to null safety * Migrate expression evaluator to null safety * format * Fix failing tests * Migrate services/chrome_proxu_service.dart to null safety * Migrate rest of the services and dwds_vm_client to null safety * Migrate package:dwds to null safety * Cleanup creation of ChromeDebugException
1 parent 0f154df commit 27cc5c9

File tree

11 files changed

+35
-46
lines changed

11 files changed

+35
-46
lines changed

dwds/lib/src/debugging/debugger.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'
1212
hide StackTrace;
1313

1414
import '../loaders/strategy.dart';
15+
import '../services/chrome_debug_exception.dart';
1516
import '../utilities/conversions.dart';
1617
import '../utilities/dart_uri.dart';
1718
import '../utilities/domain.dart';
@@ -379,7 +380,7 @@ class Debugger extends Domain {
379380

380381
Future<BoundVariable?> _boundVariable(Property property) async {
381382
// TODO(annagrin): value might be null in the future for variables
382-
// optimized by V8. Return appopriate sentinel values for them.
383+
// optimized by V8. Return appropriate sentinel values for them.
383384
if (property.value != null) {
384385
final value = property.value!;
385386
// We return one level of properties from this object. Sub-properties are
@@ -721,7 +722,7 @@ class Debugger extends Domain {
721722
try {
722723
return await _remoteDebugger.evaluateOnCallFrame(callFrameId, expression);
723724
} on ExceptionDetails catch (e) {
724-
throwChromeDebugException(
725+
throw ChromeDebugException(
725726
e.json,
726727
evalContents: expression,
727728
);
@@ -935,7 +936,7 @@ String _prettifyExtension(String member) {
935936
isSetter = member.substring(0, spaceIndex) == 'set';
936937
member = member.substring(spaceIndex + 1, member.length);
937938
} else if (poundIndex >= 0) {
938-
// Here member is a tearoff or local property getter/setter.
939+
// Here member is a tear-off or local property getter/setter.
939940
isSetter = member.substring(pipeIndex + 1, poundIndex) == 'set';
940941
member = member.replaceRange(pipeIndex + 1, poundIndex + 3, '');
941942
} else {
@@ -949,7 +950,7 @@ String _prettifyExtension(String member) {
949950
return isSetter ? '$member=' : member;
950951
}
951952

952-
/// Unescapes a DDC-escaped JS identifier name.
953+
/// Un-escapes a DDC-escaped JS identifier name.
953954
///
954955
/// Identifier names that contain illegal JS characters are escaped by DDC to a
955956
/// decimal representation of the symbol's UTF-16 value.

dwds/lib/src/debugging/modules.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Modules {
5252
return _sourceToLibrary[serverPath];
5353
}
5454

55-
Future<String?> moduleForlibrary(String libraryUri) async {
55+
Future<String?> moduleForLibrary(String libraryUri) async {
5656
await _moduleMemoizer.runOnce(_initializeMapping);
5757
return _libraryToModule[libraryUri];
5858
}

dwds/lib/src/dwds_vm_client.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void _processSendEvent(Map<String, dynamic> event,
166166
_logger.fine('Debugger ready time: $debuggerStartTime ms');
167167
} else {
168168
_logger
169-
.finest('Debugger and DevTools startup times alredy recorded.'
169+
.finest('Debugger and DevTools startup times already recorded.'
170170
' Ignoring $event.');
171171
}
172172
} else {
@@ -264,7 +264,7 @@ Future<void> _disableBreakpointsAndResume(
264264
// at this point:
265265
//
266266
// - `getIsolate()` and check for status:
267-
// the app migth still pause on existing breakpoint.
267+
// the app might still pause on existing breakpoint.
268268
//
269269
// - `pause()` and wait for `Debug.paused` event:
270270
// chrome does not send the `Debug.Paused `notification

dwds/lib/src/servers/extension_debugger.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class ExtensionDebugger implements RemoteDebugger {
304304

305305
Map<String, dynamic> _validateResult(Map<String, dynamic>? result) {
306306
if (result == null) {
307-
throw ChromeDebugException({'result': null});
307+
throw ChromeDebugException({'text': 'null result from Chrome Devtools'});
308308
}
309309
if (result.containsKey('exceptionDetails')) {
310310
throw ChromeDebugException(

dwds/lib/src/services/chrome_debug_exception.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ class ChromeDebugException extends ExceptionDetails implements Exception {
1313

1414
/// Optional, the stack where exception happened.
1515
@override
16-
final StackTrace? stackTrace;
16+
late final StackTrace? stackTrace;
1717

1818
ChromeDebugException(Map<String, dynamic> exceptionDetails,
19-
{this.additionalDetails, this.evalContents, this.stackTrace})
20-
: super(exceptionDetails);
19+
{this.additionalDetails, this.evalContents})
20+
: super(exceptionDetails) {
21+
final json = exceptionDetails['stackTrace'];
22+
stackTrace = json == null ? null : StackTrace(json);
23+
}
2124

2225
@override
2326
String toString() {

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ChromeProxyService implements VmServiceInterface {
4242
/// are dynamic and roughly map to chrome tabs.
4343
final VM _vm;
4444

45-
/// Signals when isolate is intialized.
45+
/// Signals when isolate is initialized.
4646
Future<void> get isInitialized => _initializedCompleter.future;
4747
Completer<void> _initializedCompleter = Completer<void>();
4848

@@ -165,12 +165,12 @@ class ChromeProxyService implements VmServiceInterface {
165165
return service;
166166
}
167167

168-
/// Initializes metdata in [Locations], [Modules], and [ExpressionCompiler].
168+
/// Initializes metadata in [Locations], [Modules], and [ExpressionCompiler].
169169
Future<void> _initializeEntrypoint(String entrypoint) async {
170170
_locations.initialize(entrypoint);
171171
_modules.initialize(entrypoint);
172172
_skipLists.initialize();
173-
// We do not need to wait for compiler dependencies to be udpated as the
173+
// We do not need to wait for compiler dependencies to be updated as the
174174
// [ExpressionEvaluator] is robust to evaluation requests during updates.
175175
unawaited(_updateCompilerDependencies(entrypoint));
176176
}
@@ -211,7 +211,7 @@ class ChromeProxyService implements VmServiceInterface {
211211
}
212212
// Waiting for the debugger to be ready before initializing the entrypoint.
213213
//
214-
// Note: moving `await debugger` after the `_initalizeEntryPoint` call
214+
// Note: moving `await debugger` after the `_initializeEntryPoint` call
215215
// causes `getcwd` system calls to fail. Since that system call is used
216216
// in first `Uri.base` call in the expression compiler service isolate,
217217
// the expression compiler service will fail to start.

dwds/lib/src/services/expression_evaluator.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ExpressionEvaluator {
8888
return _createError(ErrorKind.invalidInput, 'no library uri');
8989
}
9090

91-
final module = await _modules.moduleForlibrary(libraryUri);
91+
final module = await _modules.moduleForLibrary(libraryUri);
9292
if (module == null) {
9393
return _createError(ErrorKind.internal, 'no module for $libraryUri');
9494
}
@@ -187,7 +187,7 @@ class ExpressionEvaluator {
187187
ErrorKind.internal, 'no libraryUri for $dartSourcePath');
188188
}
189189

190-
final module = await _modules.moduleForlibrary(libraryUri.toString());
190+
final module = await _modules.moduleForLibrary(libraryUri.toString());
191191
if (module == null) {
192192
return _createError(
193193
ErrorKind.internal, 'no module for $libraryUri ($dartSourcePath)');
@@ -231,7 +231,7 @@ class ExpressionEvaluator {
231231
RemoteObject _formatCompilationError(String error) {
232232
// Frontend currently gives a text message including library name
233233
// and function name on compilation error. Strip this information
234-
// since it shows syntetic names that are only used for temporary
234+
// since it shows synthetic names that are only used for temporary
235235
// debug library during expression evaluation.
236236
//
237237
// TODO(annagrin): modify frontend to avoid stripping dummy names
@@ -312,7 +312,7 @@ class ExpressionEvaluator {
312312
/// this stripping code.
313313
String _maybeStripTryCatch(String jsCode) {
314314
// Match the wrapping generated by the expression compiler exactly
315-
// so the maching does not succeed naturally after the wrapping is
315+
// so the matching does not succeed naturally after the wrapping is
316316
// removed:
317317
//
318318
// Expression compiler's wrapping:

dwds/lib/src/utilities/shared.dart

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@ void serveHttpRequests(Stream<HttpRequest> requests, Handler handler,
9292
void handleErrorIfPresent(wip.WipResponse? response, {String? evalContents}) {
9393
final result = response?.result;
9494
if (result == null) return;
95-
final exceptionDetails = result['exceptionDetails'] as Map<String, dynamic>?;
96-
if (exceptionDetails != null) {
97-
throwChromeDebugException(
98-
exceptionDetails,
95+
if (result.containsKey('exceptionDetails')) {
96+
throw ChromeDebugException(
97+
result['exceptionDetails'] as Map<String, dynamic>,
9998
evalContents: evalContents,
10099
);
101100
}
@@ -106,27 +105,13 @@ void handleErrorIfPresent(wip.WipResponse? response, {String? evalContents}) {
106105
/// result or the result is null.
107106
Map<String, dynamic> getResultOrHandleError(wip.WipResponse? response,
108107
{String? evalContents}) {
109-
final result = response?.result;
110-
final resultValue = result?['result'];
111-
final exceptionDetails = result?['exceptionDetails'];
112-
if (resultValue == null || exceptionDetails != null) {
113-
throwChromeDebugException(
114-
exceptionDetails,
108+
handleErrorIfPresent(response, evalContents: evalContents);
109+
final result = response?.result?['result'];
110+
if (result == null) {
111+
throw ChromeDebugException(
112+
{'text': 'null result from Chrome Devtools'},
115113
evalContents: evalContents,
116114
);
117115
}
118-
return resultValue;
119-
}
120-
121-
Never throwChromeDebugException(Map<String, dynamic>? exceptionDetails,
122-
{String? evalContents, Object? additionalDetails}) {
123-
final stackTraceDetails = exceptionDetails?['stackTrace'];
124-
final stackTrace =
125-
stackTraceDetails == null ? null : wip.StackTrace(stackTraceDetails);
126-
throw ChromeDebugException(
127-
exceptionDetails ?? {'text': 'null result from Chrome Devtools'},
128-
evalContents: evalContents,
129-
additionalDetails: additionalDetails,
130-
stackTrace: stackTrace,
131-
);
116+
return result;
132117
}

dwds/test/fixtures/context.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class TestContext {
8585
///
8686
/// Note: build_runner-based setups ignore this setting and read
8787
/// this value from the ddc debug metadata and pass it to the
88-
/// expression compiler worker initialiation API.
88+
/// expression compiler worker initialization API.
8989
///
9090
/// TODO(annagrin): Currently setting sound null safety for frontend
9191
/// server tests fails due to missing sound SDK JavaScript and maps.

dwds/test/fixtures/fakes.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class FakeModules implements Modules {
124124
}
125125

126126
@override
127-
Future<String> moduleForlibrary(String libraryUri) {
127+
Future<String> moduleForLibrary(String libraryUri) {
128128
throw UnimplementedError();
129129
}
130130
}

dwds/test/location_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class MockModules implements Modules {
263263
}
264264

265265
@override
266-
Future<String> moduleForlibrary(String libraryUri) {
266+
Future<String> moduleForLibrary(String libraryUri) {
267267
throw UnimplementedError();
268268
}
269269
}

0 commit comments

Comments
 (0)