diff --git a/lib/src/workspace.rs b/lib/src/workspace.rs index eb2a11f1d..3f4e263d1 100644 --- a/lib/src/workspace.rs +++ b/lib/src/workspace.rs @@ -313,13 +313,14 @@ impl WorkspaceLoader { &self, user_settings: &UserSettings, store_factories: &StoreFactories, - ) -> Result { + ) -> Result { let repo_loader = RepoLoader::init(user_settings, &self.repo_dir, store_factories); let working_copy = WorkingCopy::load( repo_loader.store().clone(), self.workspace_root.clone(), self.working_copy_state_path.clone(), ); - Workspace::new(&self.workspace_root, working_copy, repo_loader) + let workspace = Workspace::new(&self.workspace_root, working_copy, repo_loader)?; + Ok(workspace) } } diff --git a/src/cli_util.rs b/src/cli_util.rs index f6183de24..c32d48b75 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -395,7 +395,7 @@ impl CommandHelper { let loader = self.workspace_loader()?; loader .load(&self.settings, &self.store_factories) - .map_err(|e| user_error(format!("{}: {}", e, e.error))) + .map_err(|err| map_workspace_load_error(err, &self.global_args)) } pub fn resolve_operation( @@ -1176,7 +1176,11 @@ fn init_workspace_loader( .unwrap_or(cwd) .to_owned() }; - WorkspaceLoader::init(&workspace_root).map_err(|err| match err { + WorkspaceLoader::init(&workspace_root).map_err(|err| map_workspace_load_error(err, global_args)) +} + +fn map_workspace_load_error(err: WorkspaceLoadError, global_args: &GlobalArgs) -> CommandError { + match err { WorkspaceLoadError::NoWorkspaceHere(wc_path) => { // Prefer user-specified workspace_path_str instead of absolute wc_path. let workspace_path_str = global_args.repository.as_deref().unwrap_or("."); @@ -1199,7 +1203,7 @@ jj init --git-repo=.", )), WorkspaceLoadError::Path(e) => user_error(format!("{}: {}", e, e.error)), WorkspaceLoadError::NonUnicodePath => user_error(err.to_string()), - }) + } } pub fn start_repo_transaction(