show the whole path in "missing mod.nu" errors (#10416)

This commit is contained in:
Antoine Stevan 2023-09-23 15:30:03 +02:00 committed by GitHub
parent b6d31e0e45
commit 6a2fd91a01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -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;
}

View File

@ -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,