Files
sdk/runtime/observatory/tests/service/evaluate_with_scope_test.dart
T
Jens Johansen bbb24d3364 [observatory] Properly handle expression compile time errors
In observatory there are two different ways to do expression evaluation.
One calls `evaluateInFrame` and catches the ServerRpcException thrown
when there's a compilation error. Another calls `evaluate` and does not
catch the ServerRpcException thrown when there's a compilation error.

This means, for instance, if evaluting an expression on an instance
and makes a typo there's suddenly a big box with scrambled javascript
on the top-right of the screen.

This CL:
* Handles the ServerRpcException thrown when there's a compilation error
  for `evaluate` as well.
* Makes both `evaluate` and `evaluateInFrame` unpack the `details` sent
  by the VM instead of printing out the textual representation of a map.
  This means that you get an error message like

```
org-dartlang-debug:synthetic_debug_expression:1:1: Error: Getter not found: 'test'.
test
^^^^
```

instead of

```
{details: org-dartlang-debug:synthetic_debug_expression:1:1: Error: Getter not found: 'test'.
test
^^^^}
```

TEST=Existing test suites.

Change-Id: I2dc3f19f024e918e8d0e9b0f4166a4ef2c6cbd9b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/186292
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2021-02-24 10:34:35 +00:00

50 lines
1.6 KiB
Dart

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:observatory/service_io.dart';
import 'package:test/test.dart';
import 'test_helper.dart';
var thing1;
var thing2;
testeeMain() {
thing1 = 3;
thing2 = 4;
}
var tests = <IsolateTest>[
(Isolate isolate) async {
Library lib = await isolate.rootLibrary.load() as Library;
Field thing1Field = await lib.variables
.singleWhere((v) => v.name == "thing1")
.load() as Field;
var thing1 = thing1Field.staticValue!;
print(thing1);
Field thing2Field = await lib.variables
.singleWhere((v) => v.name == "thing2")
.load() as Field;
var thing2 = thing2Field.staticValue!;
print(thing2);
Instance result = await lib.evaluate("x + y",
scope: <String, ServiceObject>{"x": thing1, "y": thing2}) as Instance;
expect(result.valueAsString, equals('7'));
DartError errorResult = await lib.evaluate("x + y",
scope: <String, ServiceObject>{"x": lib, "y": lib}) as DartError;
print(errorResult);
expect(errorResult.toString(),
contains("Cannot evaluate against a VM-internal object"));
errorResult = await lib.evaluate("x + y",
scope: <String, ServiceObject>{"not&an&identifier": thing1})
as DartError;
print(errorResult);
expect(errorResult.toString(), contains("invalid 'scope' parameter"));
},
];
main(args) => runIsolateTests(args, tests, testeeBefore: testeeMain);