Convert FileNotFound to named fields (#11120)

# Description

Part of #10700

# User-Facing Changes

None

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
This commit is contained in:
Eric Hodel 2023-11-21 01:08:10 -08:00 committed by GitHub
parent 0578cf85ac
commit a324a50bb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 19 additions and 10 deletions

View File

@ -107,7 +107,7 @@ impl Command for History {
)
})
})
.ok_or(ShellError::FileNotFound(head))?
.ok_or(ShellError::FileNotFound { span: head })?
.into_pipeline_data(ctrlc)),
HistoryFileFormat::Sqlite => Ok(history_reader
.and_then(|h| {
@ -119,12 +119,12 @@ impl Command for History {
create_history_record(idx, entry, long, head)
})
})
.ok_or(ShellError::FileNotFound(head))?
.ok_or(ShellError::FileNotFound { span: head })?
.into_pipeline_data(ctrlc)),
}
}
} else {
Err(ShellError::FileNotFound(head))
Err(ShellError::FileNotFound { span: head })
}
}

View File

@ -55,7 +55,9 @@ impl Command for SourceEnv {
)? {
PathBuf::from(&path)
} else {
return Err(ShellError::FileNotFound(source_filename.span));
return Err(ShellError::FileNotFound {
span: source_filename.span,
});
};
if let Some(parent) = file_path.parent() {

View File

@ -111,7 +111,7 @@ impl Command for Cp {
};
if sources.is_empty() {
return Err(ShellError::FileNotFound(src.span));
return Err(ShellError::FileNotFound { span: src.span });
}
if sources.len() > 1 && !destination.is_dir() {

View File

@ -80,7 +80,9 @@ impl Command for Mv {
arg_glob(&spanned_source, &path).map_or_else(|_| Vec::new(), Iterator::collect);
if sources.is_empty() {
return Err(ShellError::FileNotFound(spanned_source.span));
return Err(ShellError::FileNotFound {
span: spanned_source.span,
});
}
// We have two possibilities.

View File

@ -105,7 +105,7 @@ impl Command for Open {
for path in nu_engine::glob_from(&path, &cwd, call_span, None)
.map_err(|err| match err {
ShellError::DirectoryNotFound(span, _) => ShellError::FileNotFound(span),
ShellError::DirectoryNotFound(span, _) => ShellError::FileNotFound { span },
_ => err,
})?
.1

View File

@ -173,7 +173,7 @@ impl Command for UCp {
for p in paths {
let exp_files = arg_glob(&p, &cwd)?.collect::<Vec<GlobResult>>();
if exp_files.is_empty() {
return Err(ShellError::FileNotFound(p.span));
return Err(ShellError::FileNotFound { span: p.span });
};
let mut app_vals: Vec<PathBuf> = Vec::new();
for v in exp_files {

View File

@ -117,7 +117,9 @@ impl Command for NuCheck {
if let Some(path) = path {
path
} else {
return Err(ShellError::FileNotFound(path_str.span));
return Err(ShellError::FileNotFound {
span: path_str.span,
});
}
}
Err(error) => return Err(error),

View File

@ -713,7 +713,10 @@ pub enum ShellError {
/// Does the file in the error message exist? Is it readable and accessible? Is the casing right?
#[error("File not found")]
#[diagnostic(code(nu::shell::file_not_found))]
FileNotFound(#[label("file not found")] Span),
FileNotFound {
#[label("file not found")]
span: Span,
},
/// Failed to find a file during a nushell operation.
///