diff --git a/cli/src/command_error.rs b/cli/src/command_error.rs index 2ee53bed67..4471f9b6f1 100644 --- a/cli/src/command_error.rs +++ b/cli/src/command_error.rs @@ -206,6 +206,12 @@ impl From for CommandError { } } +impl From for CommandError { + fn from(err: jj_lib::file_util::PathError) -> Self { + user_error(err) + } +} + impl From for CommandError { fn from(err: config::ConfigError) -> Self { config_error(err) diff --git a/cli/src/commands/workspace.rs b/cli/src/commands/workspace.rs index 67ffa52f9f..b77ab08c3a 100644 --- a/cli/src/commands/workspace.rs +++ b/cli/src/commands/workspace.rs @@ -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() diff --git a/lib/src/file_util.rs b/lib/src/file_util.rs index 157c882542..55b24e9aab 100644 --- a/lib/src/file_util.rs +++ b/lib/src/file_util.rs @@ -31,7 +31,7 @@ pub struct PathError { pub error: io::Error, } -pub(crate) trait IoResultExt { +pub trait IoResultExt { fn context(self, path: impl AsRef) -> Result; }