Skip to content
Permalink
Browse files

devtools: handle script task panics gracefully in ConsoleActor.

  • Loading branch information...
eddyb committed Dec 5, 2014
1 parent 92a8c7a commit b328c57caa4f402f6724b5f03db7f8e775f012cc
@@ -21,7 +21,7 @@ pub trait Actor : Any {
registry: &ActorRegistry,
msg_type: &String,
msg: &json::JsonObject,
stream: &mut TcpStream) -> bool;
stream: &mut TcpStream) -> Result<bool, ()>;
fn name(&self) -> String;
}

@@ -148,13 +148,16 @@ impl ActorRegistry {

/// Attempt to process a message as directed by its `to` property. If the actor is not
/// found or does not indicate that it knew how to process the message, ignore the failure.
pub fn handle_message(&mut self, msg: &json::JsonObject, stream: &mut TcpStream) {
pub fn handle_message(&mut self,
msg: &json::JsonObject,
stream: &mut TcpStream)
-> Result<(), ()> {
let to = msg.get(&"to".to_string()).unwrap().as_string().unwrap();
match self.actors.get(&to.to_string()) {
None => println!("message received for unknown actor \"{:s}\"", to),
Some(actor) => {
let msg_type = msg.get(&"type".to_string()).unwrap().as_string().unwrap();
if !actor.handle_message(self, &msg_type.to_string(), msg, stream) {
if !try!(actor.handle_message(self, &msg_type.to_string(), msg, stream)) {
println!("unexpected message type \"{:s}\" found for actor \"{:s}\"",
msg_type, to);
}
@@ -164,5 +167,6 @@ impl ActorRegistry {
for actor in new_actors.into_iter() {
self.actors.insert(actor.name().to_string(), actor);
}
Ok(())
}
}
@@ -118,8 +118,8 @@ impl Actor for ConsoleActor {
_registry: &ActorRegistry,
msg_type: &String,
msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"getCachedMessages" => {
let types = msg.get(&"messageTypes".to_string()).unwrap().as_list().unwrap();
let /*mut*/ messages = vec!();
@@ -223,7 +223,7 @@ impl Actor for ConsoleActor {
self.script_chan.send(EvaluateJS(self.pipeline, input.clone(), chan));

//TODO: extract conversion into protocol module or some other useful place
let result = match port.recv() {
let result = match try!(port.recv_opt()) {
VoidValue => {
let mut m = TreeMap::new();
m.insert("type".to_string(), "undefined".to_string().to_json());
@@ -285,6 +285,6 @@ impl Actor for ConsoleActor {
}

_ => false
}
})
}
}
@@ -66,8 +66,8 @@ impl Actor for HighlighterActor {
_registry: &ActorRegistry,
msg_type: &String,
_msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"showBoxModel" => {
let msg = ShowBoxModelReply {
from: self.name(),
@@ -85,7 +85,7 @@ impl Actor for HighlighterActor {
}

_ => false,
}
})
}
}

@@ -103,8 +103,8 @@ impl Actor for NodeActor {
registry: &ActorRegistry,
msg_type: &String,
msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"modifyAttributes" => {
let target = msg.get(&"to".to_string()).unwrap().as_string().unwrap();
let mods = msg.get(&"modifications".to_string()).unwrap().as_list().unwrap();
@@ -123,7 +123,7 @@ impl Actor for NodeActor {
}

_ => false,
}
})
}
}

@@ -276,8 +276,8 @@ impl Actor for WalkerActor {
registry: &ActorRegistry,
msg_type: &String,
msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"querySelector" => {
let msg = QuerySelectorReply {
from: self.name(),
@@ -329,7 +329,7 @@ impl Actor for WalkerActor {
}

_ => false,
}
})
}
}

@@ -421,8 +421,8 @@ impl Actor for PageStyleActor {
registry: &ActorRegistry,
msg_type: &String,
msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"getApplied" => {
//TODO: query script for relevant applied styles to node (msg.node)
let msg = GetAppliedReply {
@@ -479,7 +479,7 @@ impl Actor for PageStyleActor {
}

_ => false,
}
})
}
}

@@ -492,8 +492,8 @@ impl Actor for InspectorActor {
registry: &ActorRegistry,
msg_type: &String,
_msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"getWalker" => {
if self.walker.borrow().is_none() {
let walker = WalkerActor {
@@ -569,6 +569,6 @@ impl Actor for InspectorActor {
}

_ => false,
}
})
}
}
@@ -54,8 +54,8 @@ impl Actor for RootActor {
registry: &ActorRegistry,
msg_type: &String,
_msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"listAddons" => {
let actor = ErrorReply {
from: "root".to_string(),
@@ -80,7 +80,7 @@ impl Actor for RootActor {
}

_ => false
}
})
}
}

@@ -78,8 +78,8 @@ impl Actor for TabActor {
registry: &ActorRegistry,
msg_type: &String,
_msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
match msg_type.as_slice() {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type.as_slice() {
"reconfigure" => {
stream.write_json_packet(&ReconfigureReply { from: self.name() });
true
@@ -125,7 +125,7 @@ impl Actor for TabActor {
}

_ => false
}
})
}
}

@@ -101,9 +101,18 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {

'outer: loop {
match stream.read_json_packet() {
Ok(json_packet) =>
actors.lock().handle_message(json_packet.as_object().unwrap(),
&mut stream),
Ok(json_packet) => {
match actors.lock().handle_message(json_packet.as_object().unwrap(),
&mut stream) {
Ok(()) => {},
Err(()) => {
println!("error: devtools actor stopped responding");
stream.close_read();
stream.close_write();
break 'outer
}
}
}
Err(e) => {
println!("error: {}", e.desc);
break 'outer

5 comments on commit b328c57

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Dec 5, 2014

saw approval from jdm
at eddyb@b328c57

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Dec 5, 2014

merging eddyb/servo/devtools-panic = b328c57 into auto

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Dec 5, 2014

eddyb/servo/devtools-panic = b328c57 merged ok, testing candidate = b8444f9

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Dec 5, 2014

fast-forwarding master to auto = b8444f9

Please sign in to comment.
You can’t perform that action at this time.