@@ -362,7 +362,7 @@ class AppInspector implements AppInspectorInterface {
362
362
}
363
363
364
364
@override
365
- Future <Obj ? > getObject (String objectId, {int ? offset, int ? count}) async {
365
+ Future <Obj > getObject (String objectId, {int ? offset, int ? count}) async {
366
366
try {
367
367
final library = await getLibrary (objectId);
368
368
if (library != null ) {
@@ -389,17 +389,22 @@ class AppInspector implements AppInspectorInterface {
389
389
'are supported for getObject' );
390
390
}
391
391
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 {
395
393
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
+ }
398
398
final serverPath = DartUri (scriptUri, _root).serverPath;
399
399
final source = await _assetReader.dartSourceContents (serverPath);
400
400
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 ' );
403
408
}
404
409
return Script (
405
410
uri: scriptRef.uri,
@@ -410,16 +415,24 @@ class AppInspector implements AppInspectorInterface {
410
415
}
411
416
412
417
@override
413
- Future <MemoryUsage ? > getMemoryUsage () async {
418
+ Future <MemoryUsage > getMemoryUsage () async {
414
419
final response = await remoteDebugger.sendCommand ('Runtime.getHeapUsage' );
415
420
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
+ }
417
425
final jsUsage = HeapUsage (result);
418
- return MemoryUsage .parse ({
426
+ final usage = MemoryUsage .parse ({
419
427
'heapUsage' : jsUsage.usedSize,
420
428
'heapCapacity' : jsUsage.totalSize,
421
429
'externalUsage' : 0 ,
422
430
});
431
+ if (usage == null ) {
432
+ throw RPCError ('getMemoryUsage' , RPCError .kInternalError,
433
+ 'Failed to parse memory usage result.' );
434
+ }
435
+ return usage;
423
436
}
424
437
425
438
/// Returns the [ScriptRef] for the provided Dart server path [uri] .
0 commit comments