mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix: inspector prompts (#13123)
This commit fixes prompts printed to the terminal when running with "--inspect" or "--inspect-brk" flags. When debugger disconnects error is no longer printed as users don't care about the reason debugger did disconnect. A message suggesting to go to "chrome://inspect" is printed if debugger is active. Additionally and information that process is waiting for debugger to connect is printed if running with "--inspect-brk" flag.
This commit is contained in:
parent
ca1fbdd636
commit
f3cd9a94b5
4 changed files with 39 additions and 12 deletions
|
@ -97,6 +97,8 @@ async fn inspector_break_on_first_line() {
|
|||
|
||||
use TestStep::*;
|
||||
let test_steps = vec![
|
||||
StdErr("Visit chrome://inspect to connect to the debugger."),
|
||||
StdErr("Deno is waiting for debugger to connect."),
|
||||
WsSend(r#"{"id":1,"method":"Runtime.enable"}"#),
|
||||
WsSend(r#"{"id":2,"method":"Debugger.enable"}"#),
|
||||
WsRecv(
|
||||
|
@ -119,10 +121,10 @@ async fn inspector_break_on_first_line() {
|
|||
|
||||
for step in test_steps {
|
||||
match step {
|
||||
StdErr(s) => assert_eq!(&stderr_lines.next().unwrap(), s),
|
||||
StdOut(s) => assert_eq!(&stdout_lines.next().unwrap(), s),
|
||||
WsRecv(s) => assert!(socket_rx.next().await.unwrap().starts_with(s)),
|
||||
WsSend(s) => socket_tx.send(s.into()).await.unwrap(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,6 +278,8 @@ async fn inspector_does_not_hang() {
|
|||
|
||||
use TestStep::*;
|
||||
let test_steps = vec![
|
||||
StdErr("Visit chrome://inspect to connect to the debugger."),
|
||||
StdErr("Deno is waiting for debugger to connect."),
|
||||
WsSend(r#"{"id":1,"method":"Runtime.enable"}"#),
|
||||
WsSend(r#"{"id":2,"method":"Debugger.enable"}"#),
|
||||
WsRecv(
|
||||
|
@ -293,6 +297,7 @@ async fn inspector_does_not_hang() {
|
|||
|
||||
for step in test_steps {
|
||||
match step {
|
||||
StdErr(s) => assert_eq!(&stderr_lines.next().unwrap(), s),
|
||||
WsRecv(s) => assert!(socket_rx.next().await.unwrap().starts_with(s)),
|
||||
WsSend(s) => socket_tx.send(s.into()).await.unwrap(),
|
||||
_ => unreachable!(),
|
||||
|
@ -397,6 +402,7 @@ async fn inspector_runtime_evaluate_does_not_crash() {
|
|||
|
||||
use TestStep::*;
|
||||
let test_steps = vec![
|
||||
StdErr("Visit chrome://inspect to connect to the debugger."),
|
||||
WsSend(r#"{"id":1,"method":"Runtime.enable"}"#),
|
||||
WsSend(r#"{"id":2,"method":"Debugger.enable"}"#),
|
||||
WsRecv(
|
||||
|
@ -555,6 +561,8 @@ async fn inspector_break_on_first_line_in_test() {
|
|||
|
||||
use TestStep::*;
|
||||
let test_steps = vec![
|
||||
StdErr("Visit chrome://inspect to connect to the debugger."),
|
||||
StdErr("Deno is waiting for debugger to connect."),
|
||||
WsSend(r#"{"id":1,"method":"Runtime.enable"}"#),
|
||||
WsSend(r#"{"id":2,"method":"Debugger.enable"}"#),
|
||||
WsRecv(
|
||||
|
@ -583,9 +591,9 @@ async fn inspector_break_on_first_line_in_test() {
|
|||
"Doesn't contain {}",
|
||||
s
|
||||
),
|
||||
StdErr(s) => assert_eq!(&stderr_lines.next().unwrap(), s),
|
||||
WsRecv(s) => assert!(socket_rx.next().await.unwrap().starts_with(s)),
|
||||
WsSend(s) => socket_tx.send(s.into()).await.unwrap(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,13 +65,18 @@ impl InspectorServer {
|
|||
&self,
|
||||
module_url: String,
|
||||
js_runtime: &mut JsRuntime,
|
||||
should_break_on_first_statement: bool,
|
||||
) {
|
||||
let inspector = js_runtime.inspector();
|
||||
let session_sender = inspector.get_session_sender();
|
||||
let deregister_rx = inspector.add_deregister_handler();
|
||||
// TODO(bartlomieju): simplify
|
||||
let info =
|
||||
InspectorInfo::new(self.host, session_sender, deregister_rx, module_url);
|
||||
let info = InspectorInfo::new(
|
||||
self.host,
|
||||
session_sender,
|
||||
deregister_rx,
|
||||
module_url,
|
||||
should_break_on_first_statement,
|
||||
);
|
||||
self.register_inspector_tx.unbounded_send(info).unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -229,6 +234,10 @@ async fn server(
|
|||
"Debugger listening on {}",
|
||||
info.get_websocket_debugger_url()
|
||||
);
|
||||
eprintln!("Visit chrome://inspect to connect to the debugger.");
|
||||
if info.should_break_on_first_statement {
|
||||
eprintln!("Deno is waiting for debugger to connect.");
|
||||
}
|
||||
if inspector_map.borrow_mut().insert(info.uuid, info).is_some() {
|
||||
panic!("Inspector UUID already in map");
|
||||
}
|
||||
|
@ -336,7 +345,7 @@ async fn pump_websocket_messages(
|
|||
.map_err(|_| ());
|
||||
|
||||
let inbound_pump = async move {
|
||||
let result = websocket_rx
|
||||
let _result = websocket_rx
|
||||
.map_ok(|msg| msg.into_data())
|
||||
.map_err(AnyError::from)
|
||||
.map_ok(|msg| {
|
||||
|
@ -345,10 +354,9 @@ async fn pump_websocket_messages(
|
|||
.try_collect::<()>()
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok(_) => eprintln!("Debugger session ended"),
|
||||
Err(err) => eprintln!("Debugger session ended: {}.", err),
|
||||
};
|
||||
// Users don't care if there was an error coming from debugger,
|
||||
// just about the fact that debugger did disconnect.
|
||||
eprintln!("Debugger session ended");
|
||||
|
||||
Ok(())
|
||||
};
|
||||
|
@ -364,6 +372,7 @@ pub struct InspectorInfo {
|
|||
pub new_session_tx: UnboundedSender<InspectorSessionProxy>,
|
||||
pub deregister_rx: oneshot::Receiver<()>,
|
||||
pub url: String,
|
||||
pub should_break_on_first_statement: bool,
|
||||
}
|
||||
|
||||
impl InspectorInfo {
|
||||
|
@ -372,6 +381,7 @@ impl InspectorInfo {
|
|||
new_session_tx: mpsc::UnboundedSender<InspectorSessionProxy>,
|
||||
deregister_rx: oneshot::Receiver<()>,
|
||||
url: String,
|
||||
should_break_on_first_statement: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
host,
|
||||
|
@ -380,6 +390,7 @@ impl InspectorInfo {
|
|||
new_session_tx,
|
||||
deregister_rx,
|
||||
url,
|
||||
should_break_on_first_statement,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -442,7 +442,11 @@ impl WebWorker {
|
|||
});
|
||||
|
||||
if let Some(server) = options.maybe_inspector_server.clone() {
|
||||
server.register_inspector(main_module.to_string(), &mut js_runtime);
|
||||
server.register_inspector(
|
||||
main_module.to_string(),
|
||||
&mut js_runtime,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
let (internal_handle, external_handle) = {
|
||||
|
|
|
@ -161,7 +161,11 @@ impl MainWorker {
|
|||
});
|
||||
|
||||
if let Some(server) = options.maybe_inspector_server.clone() {
|
||||
server.register_inspector(main_module.to_string(), &mut js_runtime);
|
||||
server.register_inspector(
|
||||
main_module.to_string(),
|
||||
&mut js_runtime,
|
||||
options.should_break_on_first_statement,
|
||||
);
|
||||
}
|
||||
|
||||
Self {
|
||||
|
|
Loading…
Reference in a new issue