Skip to content

Commit 4534124

Browse files
author
Anna Gringauze
authored
Migrate services/chrome_proxy_service to null safety (#1687)
* 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 * Made return a non-null value * Cleanup error messages in Inspector._getScript
1 parent c0d690e commit 4534124

File tree

5 files changed

+173
-155
lines changed

5 files changed

+173
-155
lines changed

dwds/lib/src/debugging/inspector.dart

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class AppInspector implements AppInspectorInterface {
362362
}
363363

364364
@override
365-
Future<Obj?> getObject(String objectId, {int? offset, int? count}) async {
365+
Future<Obj> getObject(String objectId, {int? offset, int? count}) async {
366366
try {
367367
final library = await getLibrary(objectId);
368368
if (library != null) {
@@ -389,17 +389,22 @@ class AppInspector implements AppInspectorInterface {
389389
'are supported for getObject');
390390
}
391391

392-
Future<Script?> _getScript(ScriptRef scriptRef) async {
393-
final libraryId = _scriptIdToLibraryId[scriptRef.id];
394-
final scriptUri = scriptRef.uri;
392+
Future<Script> _getScript(ScriptRef scriptRef) async {
395393
final scriptId = scriptRef.id;
396-
if (libraryId == null || scriptUri == null || scriptId == null) return null;
397-
394+
final scriptUri = scriptRef.uri;
395+
if (scriptId == null || scriptUri == null) {
396+
throwInvalidParam('getObject', 'No script info for script $scriptRef');
397+
}
398398
final serverPath = DartUri(scriptUri, _root).serverPath;
399399
final source = await _assetReader.dartSourceContents(serverPath);
400400
if (source == null) {
401-
throw RPCError('getObject', RPCError.kInvalidParams,
402-
'Failed to load script at path: $serverPath');
401+
throwInvalidParam('getObject',
402+
'No source for $scriptRef with serverPath: $serverPath');
403+
}
404+
final libraryId = _scriptIdToLibraryId[scriptId];
405+
if (libraryId == null) {
406+
throwInvalidParam('getObject',
407+
'No library for script $scriptRef with libraryId: $libraryId');
403408
}
404409
return Script(
405410
uri: scriptRef.uri,
@@ -410,16 +415,24 @@ class AppInspector implements AppInspectorInterface {
410415
}
411416

412417
@override
413-
Future<MemoryUsage?> getMemoryUsage() async {
418+
Future<MemoryUsage> getMemoryUsage() async {
414419
final response = await remoteDebugger.sendCommand('Runtime.getHeapUsage');
415420
final result = response.result;
416-
if (result == null) return null;
421+
if (result == null) {
422+
throw RPCError('getMemoryUsage', RPCError.kInternalError,
423+
'Null result from chrome Devtools.');
424+
}
417425
final jsUsage = HeapUsage(result);
418-
return MemoryUsage.parse({
426+
final usage = MemoryUsage.parse({
419427
'heapUsage': jsUsage.usedSize,
420428
'heapCapacity': jsUsage.totalSize,
421429
'externalUsage': 0,
422430
});
431+
if (usage == null) {
432+
throw RPCError('getMemoryUsage', RPCError.kInternalError,
433+
'Failed to parse memory usage result.');
434+
}
435+
return usage;
423436
}
424437

425438
/// Returns the [ScriptRef] for the provided Dart server path [uri].

dwds/lib/src/events.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class DwdsEvent {
8585

8686
DwdsEvent.getVM() : this(DwdsEventKind.getVM, {});
8787

88-
DwdsEvent.resume(String step) : this(DwdsEventKind.resume, {'step': step});
88+
DwdsEvent.resume(String? step)
89+
: this(DwdsEventKind.resume, {if (step != null) 'step': step});
8990

9091
DwdsEvent.getSourceReport() : this(DwdsEventKind.getSourceReport, {});
9192

0 commit comments

Comments
 (0)