From 6a2fd91a01c17015ad19a6e8960311311cc825de Mon Sep 17 00:00:00 2001 From: Antoine Stevan <44101798+amtoine@users.noreply.github.com> Date: Sat, 23 Sep 2023 15:30:03 +0200 Subject: [PATCH] show the whole path in "missing mod.nu" errors (#10416) --- crates/nu-parser/src/parse_keywords.rs | 5 ++++- crates/nu-protocol/src/parse_error.rs | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index c0ae78df58..8af5c5a2eb 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -1943,7 +1943,10 @@ pub fn parse_module_file_or_dir( let mod_nu_path = module_path.clone().join("mod.nu"); if !(mod_nu_path.exists() && mod_nu_path.is_file()) { - working_set.error(ParseError::ModuleMissingModNuFile(path_span)); + working_set.error(ParseError::ModuleMissingModNuFile( + module_path.path().to_string_lossy().to_string(), + path_span, + )); return None; } diff --git a/crates/nu-protocol/src/parse_error.rs b/crates/nu-protocol/src/parse_error.rs index 95f1e665eb..826e74d46c 100644 --- a/crates/nu-protocol/src/parse_error.rs +++ b/crates/nu-protocol/src/parse_error.rs @@ -212,9 +212,12 @@ pub enum ParseError { #[error("Missing mod.nu file.")] #[diagnostic( code(nu::parser::module_missing_mod_nu_file), - help("When importing a directory as a Nushell module, it needs to contain a mod.nu file (can be empty). Alternatively, you can use .nu files in the directory as modules individually.") + help("Directory {0} is missing a mod.nu file.\n\nWhen importing a directory as a Nushell module, it needs to contain a mod.nu file (can be empty). Alternatively, you can use .nu files in the directory as modules individually.") )] - ModuleMissingModNuFile(#[label = "module directory is missing a mod.nu file"] Span), + ModuleMissingModNuFile( + String, + #[label = "module directory is missing a mod.nu file"] Span, + ), #[error("Cyclical module import.")] #[diagnostic(code(nu::parser::cyclical_module_import), help("{0}"))] @@ -504,7 +507,7 @@ impl ParseError { ParseError::AliasNotValid(s) => *s, ParseError::CommandDefNotValid(s) => *s, ParseError::ModuleNotFound(s) => *s, - ParseError::ModuleMissingModNuFile(s) => *s, + ParseError::ModuleMissingModNuFile(_, s) => *s, ParseError::NamedAsModule(_, _, _, s) => *s, ParseError::ModuleDoubleMain(_, s) => *s, ParseError::InvalidModuleFileName(_, _, s) => *s,