Skip to content

Commit

Permalink
External merge tools: better error message for unsupported usage
Browse files Browse the repository at this point in the history
I've heard of one instance of a person being confused by the error.

Previously, the error was:

```
Error: Failed to load tool configuration
Caused by: To use `diffedit3` as a merge tool, the config `merge-tools.diffedit3.merge-args` must be defined (see docs for details)

```

Now, it is:

```
Error: The tool `diffedit3` cannot be used as a merge tool with `jj resolve`.
Hint: To use `diffedit3` as a merge tool, the config `merge-tools.diffedit3.merge-args` must be defined (see docs for details)
```

TODO for future PR: allow setting `merge-tools.TOOL.edit-args = false` so that
attempting to use TOOL as a diff editor fails. This would be helpful, for
example, for the `vscode` tool.
  • Loading branch information
ilyagr committed May 5, 2024
1 parent 19563fe commit 945afc3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 14 additions & 1 deletion cli/src/command_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,20 @@ impl From<ConflictResolveError> for CommandError {

impl From<MergeToolConfigError> for CommandError {
fn from(err: MergeToolConfigError) -> Self {
user_error_with_message("Failed to load tool configuration", err)
match err {
MergeToolConfigError::MergeArgsNotConfigured { ref tool_name } => {
let tool_name = tool_name.clone();
user_error_with_hint(
err,
format!(
"To use `{tool_name}` as a merge tool, the config \
`merge-tools.{tool_name}.merge-args` must be defined (see docs for \
details)"
),
)
}
_ => user_error_with_message("Failed to load tool configuration", err),
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions cli/src/merge_tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ pub enum ConflictResolveError {
pub enum MergeToolConfigError {
#[error(transparent)]
Config(#[from] ConfigError),
#[error(
"To use `{tool_name}` as a merge tool, the config `merge-tools.{tool_name}.merge-args` \
must be defined (see docs for details)"
)]
#[error("The tool `{tool_name}` cannot be used as a merge tool with `jj resolve`.")]
MergeArgsNotConfigured { tool_name: String },
}

Expand Down

0 comments on commit 945afc3

Please sign in to comment.