mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-24 21:13:47 +00:00
workspace add: add filename context to FS error
At work, a user encountered a panic upon attempting to create a dir at the line in the diff below, but it turned out to be difficult to debug because I didn't know what the path was. There already is a mechanism to add path context in the lib crate; make it available in the cli crate as well, and use the mechanism to add path context to "workspace add".
This commit is contained in:
parent
f883ce92c6
commit
1eef1a4f55
3 changed files with 9 additions and 2 deletions
|
@ -206,6 +206,12 @@ impl From<io::Error> for CommandError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<jj_lib::file_util::PathError> for CommandError {
|
||||
fn from(err: jj_lib::file_util::PathError) -> Self {
|
||||
user_error(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<config::ConfigError> for CommandError {
|
||||
fn from(err: config::ConfigError) -> Self {
|
||||
config_error(err)
|
||||
|
|
|
@ -21,6 +21,7 @@ use clap::Subcommand;
|
|||
use itertools::Itertools;
|
||||
use jj_lib::commit::CommitIteratorExt;
|
||||
use jj_lib::file_util;
|
||||
use jj_lib::file_util::IoResultExt;
|
||||
use jj_lib::object_id::ObjectId;
|
||||
use jj_lib::op_store::{OpStoreError, WorkspaceId};
|
||||
use jj_lib::operation::Operation;
|
||||
|
@ -137,7 +138,7 @@ fn cmd_workspace_add(
|
|||
if destination_path.exists() {
|
||||
return Err(user_error("Workspace already exists"));
|
||||
} else {
|
||||
fs::create_dir(&destination_path).unwrap();
|
||||
fs::create_dir(&destination_path).context(&destination_path)?;
|
||||
}
|
||||
let name = if let Some(name) = &args.name {
|
||||
name.to_string()
|
||||
|
|
|
@ -31,7 +31,7 @@ pub struct PathError {
|
|||
pub error: io::Error,
|
||||
}
|
||||
|
||||
pub(crate) trait IoResultExt<T> {
|
||||
pub trait IoResultExt<T> {
|
||||
fn context(self, path: impl AsRef<Path>) -> Result<T, PathError>;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue