dart:developer registerExtension()

149 views
Skip to first unread message

Devon Carew

unread,
Dec 4, 2015, 4:58:16 PM12/4/15
to observato...@dartlang.org
Hey observatory folks, I have a question about dart:developer registerExtension(). It looks like it's meant to allow Dart code to expose details about itself to a debugger client. A dart library or app can basically add new grammar to the server protocol; it that correct?

I've played with it but was not able to get it working. I created a dart app which registered a new extension ("foo"), and when the app was paused I tried to invoke that handler from a service protocol client (the atom debugger). I only ever got errors back from the "foo" command. Other commands worked fine ("getVersion", ...). This is for 1.14.0-dev.1.0. Is this functionality not hooked, am I mis-understanding what it is for, or am I just using it incorrectly?

https://api.dartlang.org/1.13.0/dart-developer/registerExtension.html



--
Devon Carew
Software Engineer
Google, Inc.

Ryan Macnak

unread,
Dec 7, 2015, 3:53:34 PM12/7/15
to Devon Carew, observato...@dartlang.org
On Fri, Dec 4, 2015 at 1:58 PM, 'Devon Carew' via Dart VM Observatory Discuss <observato...@dartlang.org> wrote:
Hey observatory folks, I have a question about dart:developer registerExtension(). It looks like it's meant to allow Dart code to expose details about itself to a debugger client. A dart library or app can basically add new grammar to the server protocol; it that correct?

Yes, Dart code can add an RPC method.

I've played with it but was not able to get it working. I created a dart app which registered a new extension ("foo"), and when the app was paused I tried to invoke that handler from a service protocol client (the atom debugger). I only ever got errors back from the "foo" command. Other commands worked fine ("getVersion", ...). This is for 1.14.0-dev.1.0. Is this functionality not hooked, am I mis-understanding what it is for, or am I just using it incorrectly?

I don't see anything wrong from your description. What error are you getting?
 

--
You received this message because you are subscribed to the Google Groups "Dart VM Observatory Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to observatory-dis...@dartlang.org.

Devon Carew

unread,
Dec 7, 2015, 4:23:22 PM12/7/15
to Ryan Macnak, observato...@dartlang.org
The code under test registers the 'foo' handler:

registerExtension('foo', fooHandler);

and fooHandler looks like:

Future<ServiceExtensionResponse> fooHandler(String method, Map parameters) {
  return new Future.value(new ServiceExtensionResponse.result('bar'));
}

==> {"id":"15","method":"foo"}
<== {"jsonrpc":"2.0", "error":{"code":-32601,"message":"Method not found","data":{"request":{"method":"foo","params":{}}}},"id":"15"}

==> {"id":"16","method":"foo","params":{"arg":123}}
<== {"jsonrpc":"2.0", "error":{"code":-32601,"message":"Method not found","data":{"request":{"method":"foo","params":{"arg":"123"}}}},"id":"16"}

Devon Carew

unread,
Dec 7, 2015, 4:24:57 PM12/7/15
to Ryan Macnak, observato...@dartlang.org
If nothing jumps out there, is there some example code that uses service extensions?

Ryan Macnak

unread,
Dec 7, 2015, 6:28:09 PM12/7/15
to Devon Carew, observato...@dartlang.org
There is a unit test at sdk/runtime/observatory/tests/service/developer_extension_test.dart.

Devon Carew

unread,
Dec 7, 2015, 8:40:22 PM12/7/15
to Ryan Macnak, observato...@dartlang.org
Ah, it looks like the caller has to include the 'isolateId' as a param to the service call. Once I do that I start getting responses. Without it I just get the -32601 method not found errors. Is the param intended to be required? If so, the docs should probably be updated to the effect.

Thanks for the pointer to the test case,

Devon

Todd Turnidge

unread,
Dec 9, 2015, 4:59:25 PM12/9/15
to Devon Carew, Ryan Macnak, observato...@dartlang.org
Can you file a bug to get a better error message?

Devon Carew

unread,
Dec 9, 2015, 5:12:52 PM12/9/15
to Todd Turnidge, Ryan Macnak, observato...@dartlang.org

John Mccutchan

unread,
Dec 10, 2015, 3:06:02 AM12/10/15
to Devon Carew, Todd Turnidge, Ryan Macnak, observato...@dartlang.org

The problem is that service protocol requests without an isolateId parameter are routed to the service isolate and not the isolate that called registerExtension. Given what the service isolate knows, it is returning the correct error code.

Almost all service protocol requests require a target isolate (with few exceptions for getFlags and getVM).

John

Devon Carew

unread,
Dec 10, 2015, 11:50:52 AM12/10/15
to John Mccutchan, Todd Turnidge, Ryan Macnak, observato...@dartlang.org
Yeah, this makes sense after the fact, but it was hard to diagnose, esp. given the error message - while correct - was misleading.

Perhaps the resolution here is to document service extensions a bit more? Writing them will probably be an infrequent event, but it'd be nice to have a quick walkthrough somewhere.


Todd Turnidge

unread,
Dec 10, 2015, 1:24:53 PM12/10/15
to Devon Carew, John Mccutchan, Ryan Macnak, observato...@dartlang.org
Maybe the service isolate can notice that it got a request that requires an isolate parameter...
Reply all
Reply to author
Forward
0 new messages