forked from extern/nushell
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:
parent
0578cf85ac
commit
a324a50bb7
@ -107,7 +107,7 @@ impl Command for History {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.ok_or(ShellError::FileNotFound(head))?
|
.ok_or(ShellError::FileNotFound { span: head })?
|
||||||
.into_pipeline_data(ctrlc)),
|
.into_pipeline_data(ctrlc)),
|
||||||
HistoryFileFormat::Sqlite => Ok(history_reader
|
HistoryFileFormat::Sqlite => Ok(history_reader
|
||||||
.and_then(|h| {
|
.and_then(|h| {
|
||||||
@ -119,12 +119,12 @@ impl Command for History {
|
|||||||
create_history_record(idx, entry, long, head)
|
create_history_record(idx, entry, long, head)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.ok_or(ShellError::FileNotFound(head))?
|
.ok_or(ShellError::FileNotFound { span: head })?
|
||||||
.into_pipeline_data(ctrlc)),
|
.into_pipeline_data(ctrlc)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(ShellError::FileNotFound(head))
|
Err(ShellError::FileNotFound { span: head })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
crates/nu-command/src/env/source_env.rs
vendored
4
crates/nu-command/src/env/source_env.rs
vendored
@ -55,7 +55,9 @@ impl Command for SourceEnv {
|
|||||||
)? {
|
)? {
|
||||||
PathBuf::from(&path)
|
PathBuf::from(&path)
|
||||||
} else {
|
} else {
|
||||||
return Err(ShellError::FileNotFound(source_filename.span));
|
return Err(ShellError::FileNotFound {
|
||||||
|
span: source_filename.span,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(parent) = file_path.parent() {
|
if let Some(parent) = file_path.parent() {
|
||||||
|
@ -111,7 +111,7 @@ impl Command for Cp {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if sources.is_empty() {
|
if sources.is_empty() {
|
||||||
return Err(ShellError::FileNotFound(src.span));
|
return Err(ShellError::FileNotFound { span: src.span });
|
||||||
}
|
}
|
||||||
|
|
||||||
if sources.len() > 1 && !destination.is_dir() {
|
if sources.len() > 1 && !destination.is_dir() {
|
||||||
|
@ -80,7 +80,9 @@ impl Command for Mv {
|
|||||||
arg_glob(&spanned_source, &path).map_or_else(|_| Vec::new(), Iterator::collect);
|
arg_glob(&spanned_source, &path).map_or_else(|_| Vec::new(), Iterator::collect);
|
||||||
|
|
||||||
if sources.is_empty() {
|
if sources.is_empty() {
|
||||||
return Err(ShellError::FileNotFound(spanned_source.span));
|
return Err(ShellError::FileNotFound {
|
||||||
|
span: spanned_source.span,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have two possibilities.
|
// We have two possibilities.
|
||||||
|
@ -105,7 +105,7 @@ impl Command for Open {
|
|||||||
|
|
||||||
for path in nu_engine::glob_from(&path, &cwd, call_span, None)
|
for path in nu_engine::glob_from(&path, &cwd, call_span, None)
|
||||||
.map_err(|err| match err {
|
.map_err(|err| match err {
|
||||||
ShellError::DirectoryNotFound(span, _) => ShellError::FileNotFound(span),
|
ShellError::DirectoryNotFound(span, _) => ShellError::FileNotFound { span },
|
||||||
_ => err,
|
_ => err,
|
||||||
})?
|
})?
|
||||||
.1
|
.1
|
||||||
|
@ -173,7 +173,7 @@ impl Command for UCp {
|
|||||||
for p in paths {
|
for p in paths {
|
||||||
let exp_files = arg_glob(&p, &cwd)?.collect::<Vec<GlobResult>>();
|
let exp_files = arg_glob(&p, &cwd)?.collect::<Vec<GlobResult>>();
|
||||||
if exp_files.is_empty() {
|
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();
|
let mut app_vals: Vec<PathBuf> = Vec::new();
|
||||||
for v in exp_files {
|
for v in exp_files {
|
||||||
|
@ -117,7 +117,9 @@ impl Command for NuCheck {
|
|||||||
if let Some(path) = path {
|
if let Some(path) = path {
|
||||||
path
|
path
|
||||||
} else {
|
} else {
|
||||||
return Err(ShellError::FileNotFound(path_str.span));
|
return Err(ShellError::FileNotFound {
|
||||||
|
span: path_str.span,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(error) => return Err(error),
|
Err(error) => return Err(error),
|
||||||
|
@ -713,7 +713,10 @@ pub enum ShellError {
|
|||||||
/// Does the file in the error message exist? Is it readable and accessible? Is the casing right?
|
/// Does the file in the error message exist? Is it readable and accessible? Is the casing right?
|
||||||
#[error("File not found")]
|
#[error("File not found")]
|
||||||
#[diagnostic(code(nu::shell::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.
|
/// Failed to find a file during a nushell operation.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user