Restore path type behavior (#13006)

# Description
Restores `path type` to return an empty string on error like it did pre
0.94.0.
This commit is contained in:
Ian Manske 2024-05-30 13:42:22 +00:00 committed by GitHub
parent 40772fea15
commit 31f3d2f664
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -104,10 +104,9 @@ If nothing is found, an empty string will be returned."#
fn path_type(path: &Path, span: Span, args: &Arguments) -> Value {
let path = nu_path::expand_path_with(path, &args.pwd, true);
match std::fs::symlink_metadata(path) {
Ok(metadata) => Value::string(get_file_type(&metadata), span),
Err(err) => Value::error(err.into(), span),
}
let meta = path.symlink_metadata();
let ty = meta.as_ref().map(get_file_type).unwrap_or("");
Value::string(ty, span)
}
fn get_file_type(md: &std::fs::Metadata) -> &str {