From ee904ec06c1a3b3d4e4a87898e777e2f9b587b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 15 Oct 2024 22:51:39 +0100 Subject: fix: add hint for missing `document` global in terminal error (#26218) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This came up on Discord as a question so I thought it's worth adding a hint for this as it might be a common pitfall. --------- Signed-off-by: Bartek IwaƄczuk Co-authored-by: David Sherret --- runtime/Cargo.toml | 1 + runtime/fmt_errors.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) (limited to 'runtime') diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index ba9dc6243..6cb00a97e 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -100,6 +100,7 @@ deno_websocket.workspace = true deno_webstorage.workspace = true node_resolver = { workspace = true, features = ["sync"] } +color-print.workspace = true dlopen2.workspace = true encoding_rs.workspace = true fastwebsockets.workspace = true diff --git a/runtime/fmt_errors.rs b/runtime/fmt_errors.rs index 0d4274e8a..2d9d09a29 100644 --- a/runtime/fmt_errors.rs +++ b/runtime/fmt_errors.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. //! This mod provides DenoError to unify errors across Deno. +use color_print::cstr; use deno_core::error::format_frame; use deno_core::error::JsError; use deno_terminal::colors::cyan; @@ -367,6 +368,16 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec { ] ) ]; + } else if msg.contains("document is not defined") { + return vec![ + FixSuggestion::info(cstr!( + "document global is not available in Deno." + )), + FixSuggestion::hint_multiline(&[ + cstr!("Use a library like happy-dom, deno_dom, linkedom or JSDom"), + cstr!("and setup the document global according to the library documentation."), + ]), + ]; } } -- cgit v1.2.3