1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00

feat(cli/hmr): print compile error with exception details

This commit is contained in:
Elias Rhouzlane 2025-01-09 09:08:06 +01:00
parent ce0968ef3a
commit d9c884da65
2 changed files with 23 additions and 7 deletions

View file

@ -291,8 +291,10 @@ pub type UnserializableValue = String;
/// <https://chromedevtools.github.io/devtools-protocol/tot/Debugger/#method-setScriptSource>
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SetScriptSourceResponse {
pub status: Status,
pub exception_details: Option<ExceptionDetails>,
}
#[derive(Debug, Deserialize)]

View file

@ -19,14 +19,28 @@ use crate::emit::Emitter;
use crate::util::file_watcher::WatcherCommunicator;
use crate::util::file_watcher::WatcherRestartMode;
fn explain(status: &cdp::Status) -> &'static str {
fn explain(
status: &cdp::Status,
exception_details: &Option<cdp::ExceptionDetails>,
) -> String {
match status {
cdp::Status::Ok => "OK",
cdp::Status::CompileError => "compile error",
cdp::Status::BlockedByActiveGenerator => "blocked by active generator",
cdp::Status::BlockedByActiveFunction => "blocked by active function",
cdp::Status::Ok => "OK".to_string(),
cdp::Status::CompileError => {
if let Some(details) = exception_details {
let (message, description) = details.get_message_and_description();
format!("compile error: {} - {}", message, description)
} else {
"compile error: No exception details available".to_string()
}
}
cdp::Status::BlockedByActiveGenerator => {
"blocked by active generator".to_string()
}
cdp::Status::BlockedByActiveFunction => {
"blocked by active function".to_string()
}
cdp::Status::BlockedByTopLevelEsModuleChange => {
"blocked by top-level ES module change"
"blocked by top-level ES module change".to_string()
}
}
}
@ -154,7 +168,7 @@ impl crate::worker::HmrRunner for HmrRunner {
break;
}
self.watcher_communicator.print(format!("Failed to reload module {}: {}.", module_url, colors::gray(explain(&result.status))));
self.watcher_communicator.print(format!("Failed to reload module {}: {}.", module_url, colors::gray(&explain(&result.status, &result.exception_details))));
if should_retry(&result.status) && tries <= 2 {
tries += 1;
tokio::time::sleep(std::time::Duration::from_millis(100)).await;