summaryrefslogtreecommitdiff
path: root/cli/tools/run/hmr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools/run/hmr.rs')
-rw-r--r--cli/tools/run/hmr.rs21
1 files changed, 4 insertions, 17 deletions
diff --git a/cli/tools/run/hmr.rs b/cli/tools/run/hmr.rs
index fb6651fed..0842c0084 100644
--- a/cli/tools/run/hmr.rs
+++ b/cli/tools/run/hmr.rs
@@ -8,24 +8,15 @@ use deno_core::error::generic_error;
use deno_core::error::AnyError;
use deno_core::futures::StreamExt;
use deno_core::serde_json::json;
-use deno_core::serde_json::Value;
use deno_core::serde_json::{self};
use deno_core::url::Url;
use deno_core::LocalInspectorSession;
use deno_runtime::colors;
-use serde::Deserialize;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use tokio::select;
-// TODO(bartlomieju): the same thing is used in the REPL. Deduplicate.
-#[derive(Debug, Deserialize)]
-pub struct RpcNotification {
- pub method: String,
- pub params: Value,
-}
-
fn explain(status: &cdp::Status) -> &'static str {
match status {
cdp::Status::Ok => "OK",
@@ -177,15 +168,11 @@ impl HmrRunner {
select! {
biased;
Some(notification) = session_rx.next() => {
- let notification = serde_json::from_value::<RpcNotification>(notification)?;
- // TODO(bartlomieju): this is not great... and the code is duplicated with the REPL.
+ let notification = serde_json::from_value::<cdp::Notification>(notification)?;
if notification.method == "Runtime.exceptionThrown" {
- let params = notification.params;
- let exception_details = params.get("exceptionDetails").unwrap().as_object().unwrap();
- let text = exception_details.get("text").unwrap().as_str().unwrap();
- let exception = exception_details.get("exception").unwrap().as_object().unwrap();
- let description = exception.get("description").and_then(|d| d.as_str()).unwrap_or("undefined");
- break Err(generic_error(format!("{text} {description}")));
+ let exception_thrown = serde_json::from_value::<cdp::ExceptionThrown>(notification.params)?;
+ let (message, description) = exception_thrown.exception_details.get_message_and_description();
+ break Err(generic_error(format!("{} {}", message, description)));
} else if notification.method == "Debugger.scriptParsed" {
let params = serde_json::from_value::<cdp::ScriptParsed>(notification.params)?;
if params.url.starts_with("file://") {