Skip to content

Update eval_service.dart to handle case when isolateRefId is null. #5026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ class EvalService extends DisposableController with AutoDisposeControllerMixin {
return serviceManager.service!;
}

String get _isolateRefId {
final id = serviceManager.isolateManager.selectedIsolate.value?.id;
// TODO(polina-c): it is not clear why returning '' is ok.
if (id == null) return '';
return id;
String? get _isolateRefId {
return serviceManager.isolateManager.selectedIsolate.value?.id;
}

/// Returns the class for the provided [ClassRef].
Expand Down Expand Up @@ -57,15 +54,17 @@ class EvalService extends DisposableController with AutoDisposeControllerMixin {
/// Get the populated [Obj] object, given an [ObjRef].
///
/// The return value can be one of [Obj] or [Sentinel].
Future<Obj> getObject(ObjRef objRef) {
return _service.getObject(_isolateRefId, objRef.id!);
Future<Obj?> getObject(ObjRef objRef) async {
final ref = _isolateRefId;
if (ref == null) return Future.value();
return await _service.getObject(ref, objRef.id!);
}

/// Evaluate the given expression in the context of the currently selected
/// stack frame, or the top frame if there is no current selection.
///
/// This will fail if the application is not currently paused.
Future<Response> evalAtCurrentFrame(String expression) {
Future<Response> evalAtCurrentFrame(String expression) async {
final appState = serviceManager.appState;

if (!serviceManager.isMainIsolatePaused) {
Expand All @@ -90,8 +89,20 @@ class EvalService extends DisposableController with AutoDisposeControllerMixin {
);
}

final isolateRefId = _isolateRefId;

if (isolateRefId == null) {
return Future.error(
RPCError.withDetails(
'evaluateInFrame',
RPCError.kServerError,
'isolateRefId is null',
),
);
}

return _service.evaluateInFrame(
_isolateRefId,
isolateRefId,
frame.index!,
expression,
disableBreakpoints: true,
Expand Down