diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-12-18 11:43:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-18 11:43:02 +0100 |
commit | a44a5de43013becb91e4725e508051e62f628467 (patch) | |
tree | f12a4135816cea35f4853ff2730a0df2275091e5 /cli/tools/repl/mod.rs | |
parent | 9ede8d7b69c1d2859bb03e5bdffd7407042914ec (diff) |
refactor: factor out cdp::ExceptionThrown notification (#21623)
Just removing some duplicated code.
Diffstat (limited to 'cli/tools/repl/mod.rs')
-rw-r--r-- | cli/tools/repl/mod.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs index 3700911d6..4b7453cb6 100644 --- a/cli/tools/repl/mod.rs +++ b/cli/tools/repl/mod.rs @@ -3,11 +3,13 @@ use crate::args::CliOptions; use crate::args::Flags; use crate::args::ReplFlags; +use crate::cdp; use crate::colors; use crate::factory::CliFactory; use crate::file_fetcher::FileFetcher; use deno_core::error::AnyError; use deno_core::futures::StreamExt; +use deno_core::serde_json; use deno_core::unsync::spawn_blocking; use deno_runtime::permissions::Permissions; use deno_runtime::permissions::PermissionsContainer; @@ -69,14 +71,12 @@ async fn read_line_and_poll( } message = notifications.next() => { if let Some(message) = message { - let method = message.get("method").unwrap().as_str().unwrap(); - if method == "Runtime.exceptionThrown" { - let params = message.get("params").unwrap().as_object().unwrap(); - 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"); - println!("{text} {description}"); + let notification: cdp::Notification = serde_json::from_value(message).unwrap(); + eprintln!("notification {:#?}", notification); + if notification.method == "Runtime.exceptionThrown" { + let exception_thrown: cdp::ExceptionThrown = serde_json::from_value(notification.params).unwrap(); + let (message, description) = exception_thrown.exception_details.get_message_and_description(); + println!("{} {}", message, description); } } } |