Specify which file not found in error (#11868)

# Description
Currently, `ShellError::FileNotFound` shows the span where the error
occurred but doesn't say which file wasn't found. This PR makes it so
the help includes that (like the `DirectoryNotFound` error).

# User-Facing Changes
No breaking changes, it's just that when a file can't be found, the help
will say which file couldn't be found:


![image](https://github.com/nushell/nushell/assets/45539777/e52f1e65-55c1-4cd2-8108-a4ccc334a66f)
This commit is contained in:
Yash Thakur
2024-02-21 08:27:13 -05:00
committed by GitHub
parent 1058707a29
commit 6ff3a4180b
8 changed files with 39 additions and 16 deletions

View File

@ -72,7 +72,7 @@ impl Command for History {
} else {
let history_reader: Option<Box<dyn ReedlineHistory>> = match history.file_format {
HistoryFileFormat::Sqlite => {
SqliteBackedHistory::with_file(history_path, None, None)
SqliteBackedHistory::with_file(history_path.clone(), None, None)
.map(|inner| {
let boxed: Box<dyn ReedlineHistory> = Box::new(inner);
boxed
@ -80,14 +80,15 @@ impl Command for History {
.ok()
}
HistoryFileFormat::PlainText => {
FileBackedHistory::with_file(history.max_size as usize, history_path)
.map(|inner| {
let boxed: Box<dyn ReedlineHistory> = Box::new(inner);
boxed
})
.ok()
}
HistoryFileFormat::PlainText => FileBackedHistory::with_file(
history.max_size as usize,
history_path.clone(),
)
.map(|inner| {
let boxed: Box<dyn ReedlineHistory> = Box::new(inner);
boxed
})
.ok(),
};
match history.file_format {
@ -107,7 +108,10 @@ impl Command for History {
)
})
})
.ok_or(ShellError::FileNotFound { span: head })?
.ok_or(ShellError::FileNotFound {
file: history_path.display().to_string(),
span: head,
})?
.into_pipeline_data(ctrlc)),
HistoryFileFormat::Sqlite => Ok(history_reader
.and_then(|h| {
@ -119,12 +123,18 @@ impl Command for History {
create_history_record(idx, entry, long, head)
})
})
.ok_or(ShellError::FileNotFound { span: head })?
.ok_or(ShellError::FileNotFound {
file: history_path.display().to_string(),
span: head,
})?
.into_pipeline_data(ctrlc)),
}
}
} else {
Err(ShellError::FileNotFound { span: head })
Err(ShellError::FileNotFound {
file: "history file".into(),
span: head,
})
}
}