Skip to content
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

send pageErrors to devtools console #21678

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -27,7 +27,7 @@ trait EncodableConsoleMessage {
impl EncodableConsoleMessage for CachedConsoleMessage {
fn encode(&self) -> serde_json::Result<String> {
match *self {
CachedConsoleMessage::PageError(ref a) => serde_json::to_string(a),
CachedConsoleMessage::PageErrorAPI(ref a) => serde_json::to_string(a),
CachedConsoleMessage::ConsoleAPI(ref a) => serde_json::to_string(a),
}
}
@@ -37,7 +37,7 @@ use actors::timeline::TimelineActor;
use actors::worker::WorkerActor;
use devtools_traits::{ChromeToDevtoolsControlMsg, ConsoleMessage, DevtoolsControlMsg};
use devtools_traits::{DevtoolScriptControlMsg, DevtoolsPageInfo, LogLevel, NetworkEvent};
use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId};
use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId, PageErrorAPI};
use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::PipelineId;
use protocol::JsonPacketStream;
@@ -70,6 +70,15 @@ mod actors {
}
mod protocol;

#[derive(Serialize)]
struct ConsolePageErrorCall {
from: String,
#[serde(rename = "type")]
type_: String,
#[serde(rename = "pageError")]
page_error: PageErrorAPI,
}

#[derive(Serialize)]
struct ConsoleAPICall {
from: String,
@@ -285,6 +294,37 @@ fn run_server(
actors.register(Box::new(thread));
}

fn handle_console_page_error_message(

This comment has been minimized.

Copy link
@jdm

jdm Oct 31, 2018

Member

Let's call this handle_page_error_message.

actors: Arc<Mutex<ActorRegistry>>,
id: PipelineId,
worker_id: Option<WorkerId>,
page_error: PageErrorAPI,
actor_pipelines: &HashMap<PipelineId, String>,
actor_workers: &HashMap<(PipelineId, WorkerId), String>,
) {
let console_actor_name = match find_console_actor(
actors.clone(),
id,
worker_id,
actor_workers,
actor_pipelines,
) {
Some(name) => name,
None => return,
};
let actors = actors.lock().unwrap();
let console_actor = actors.find::<ConsoleActor>(&console_actor_name);

let msg = ConsolePageErrorCall {
from: console_actor.name.clone(),
type_: "pageError".to_owned(),
page_error: page_error
};
for stream in &mut *console_actor.streams.borrow_mut() {
stream.write_json_packet(&msg);
}
}

fn handle_console_message(
actors: Arc<Mutex<ActorRegistry>>,
id: PipelineId,
@@ -535,6 +575,15 @@ fn run_server(
&mut actor_workers,
pageinfo,
),
DevtoolsControlMsg::FromScript(ScriptToDevtoolsControlMsg::PageErrorAPI(id, page_error, worker_id)) => {
handle_console_page_error_message(
actors.clone(),
id,
worker_id,
page_error,
&actor_pipelines,
&actor_workers);
},
DevtoolsControlMsg::FromScript(ScriptToDevtoolsControlMsg::ConsoleAPI(
id,
console_message,
@@ -83,6 +83,7 @@ pub enum ScriptToDevtoolsControlMsg {
),
/// A particular page has invoked the console API.
ConsoleAPI(PipelineId, ConsoleMessage, Option<WorkerId>),
PageErrorAPI(PipelineId, PageErrorAPI, Option<WorkerId>),

This comment has been minimized.

Copy link
@jdm

jdm Oct 31, 2018

Member

Add /// An unhandled exception has occurred in a particular page. Also I think PageError is more clear; the previous message is ConsoleAPI because it is a message for the methods of the Console API.

/// An animation frame with the given timestamp was processed in a script thread.
/// The actor with the provided name should be notified.
FramerateTick(String, f64),
@@ -261,9 +262,7 @@ bitflags! {
}

#[derive(Debug, Deserialize, Serialize)]
pub struct PageError {
#[serde(rename = "_type")]
pub type_: String,
pub struct PageErrorAPI {
pub errorMessage: String,
pub sourceName: String,
pub lineText: String,
@@ -293,7 +292,7 @@ pub struct ConsoleAPI {

#[derive(Debug, Deserialize, Serialize)]
pub enum CachedConsoleMessage {
PageError(PageError),
PageErrorAPI(PageErrorAPI),
ConsoleAPI(ConsoleAPI),
}

@@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use devtools_traits::{AutoMargins, CachedConsoleMessage, CachedConsoleMessageTypes};
use devtools_traits::{ComputedNodeLayout, ConsoleAPI, PageError};
use devtools_traits::{ComputedNodeLayout, ConsoleAPI, PageErrorAPI};
use devtools_traits::{EvaluateJSReply, Modification, NodeInfo, TimelineMarker};
use devtools_traits::TimelineMarkerType;
use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods;
@@ -173,8 +173,7 @@ pub fn handle_get_cached_messages(_pipeline_id: PipelineId,
if message_types.contains(CachedConsoleMessageTypes::PAGE_ERROR) {
// TODO: make script error reporter pass all reported errors
// to devtools and cache them for returning here.
let msg = PageError {
type_: "PageError".to_owned(),
let msg = PageErrorAPI {
errorMessage: "page error test".to_owned(),
sourceName: String::new(),
lineText: String::new(),
@@ -188,7 +187,7 @@ pub fn handle_get_cached_messages(_pipeline_id: PipelineId,
strict: false,
private: false,
};
messages.push(CachedConsoleMessage::PageError(msg));
messages.push(CachedConsoleMessage::PageErrorAPI(msg));
}
if message_types.contains(CachedConsoleMessageTypes::CONSOLE_API) {
// TODO: do for real
@@ -1,8 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId};
use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId, PageErrorAPI};
use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::EventSourceBinding::EventSourceBinding::EventSourceMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
@@ -377,10 +376,34 @@ impl GlobalScope {

// Step 9.
if event_status == EventStatus::NotCanceled {
if let Some(chan) = self.devtools_chan() {

This comment has been minimized.

Copy link
@jdm

jdm Oct 31, 2018

Member

We should only report the error to the devtools if we don't forward it to a worker object in the code that follows this block.

let worker_id = self.downcast::<WorkerGlobalScope>().map(|worker| {
worker.get_worker_id()
});

let msg = ScriptToDevtoolsControlMsg::PageErrorAPI(self.pipeline_id(), PageErrorAPI {
lineText: String::new(),
errorMessage: error_info.message.as_str().into(),
sourceName: error_info.filename.as_str().into(),
lineNumber: error_info.lineno,
columnNumber: error_info.column,
category: String::new(),
timeStamp: 0,
error: false,
warning: false,
exception: false,

This comment has been minimized.

Copy link
@jdm

jdm Oct 31, 2018

Member

This should be true.

strict: false,
private: false,
}, worker_id);

chan.send(msg).unwrap();
}

// https://html.spec.whatwg.org/multipage/#runtime-script-errors-2
if let Some(dedicated) = self.downcast::<DedicatedWorkerGlobalScope>() {
dedicated.forward_error_to_worker_object(error_info);
}

}

}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.