Skip to content

Commit

Permalink
cleanup: remove remaining ": {source}" from error message templates
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Feb 4, 2024
1 parent 1efadd9 commit 77ceadb
Show file tree
Hide file tree
Showing 18 changed files with 79 additions and 81 deletions.
8 changes: 4 additions & 4 deletions cli/src/merge_tools/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ use thiserror::Error;

#[derive(Debug, Error)]
pub enum BuiltinToolError {
#[error("Failed to record changes: {0}")]
#[error("Failed to record changes")]
Record(#[from] scm_record::RecordError),
#[error(transparent)]
ReadFileBackend(BackendError),
#[error("Failed to read file {path:?} with ID {id}: {source}", id = id.hex())]
#[error("Failed to read file {path:?} with ID {id}", id = id.hex())]
ReadFileIo {
path: RepoPathBuf,
id: FileId,
source: std::io::Error,
},
#[error(transparent)]
ReadSymlink(BackendError),
#[error("Failed to decode UTF-8 text for item {item} (this should not happen): {source}")]
#[error("Failed to decode UTF-8 text for item {item} (this should not happen)")]
DecodeUtf8 {
source: std::str::Utf8Error,
item: &'static str,
},
#[error("Rendering {item} {id} is unimplemented for the builtin difftool/mergetool")]
Unimplemented { item: &'static str, id: String },
#[error("Backend error: {0}")]
#[error("Backend error")]
BackendError(#[from] jj_lib::backend::BackendError),
}

Expand Down
15 changes: 6 additions & 9 deletions cli/src/merge_tools/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,37 +107,34 @@ impl ExternalMergeTool {

#[derive(Debug, Error)]
pub enum ExternalToolError {
#[error("Invalid config: {0}")]
#[error("Invalid config")]
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)"
)]
MergeArgsNotConfigured { tool_name: String },
#[error("Error setting up temporary directory: {0}")]
#[error("Error setting up temporary directory")]
SetUpDir(#[source] std::io::Error),
// TODO: Remove the "(run with --verbose to see the exact invocation)"
// from this and other errors. Print it as a hint but only if --verbose is *not* set.
#[error(
"Error executing '{tool_binary}' (run with --verbose to see the exact invocation). \
{source}"
)]
#[error("Error executing '{tool_binary}' (run with --verbose to see the exact invocation)")]
FailedToExecute {
tool_binary: String,
#[source]
source: std::io::Error,
},
#[error("{}", format_tool_aborted(.exit_status))]
ToolAborted { exit_status: ExitStatus },
#[error("I/O error: {0}")]
#[error("I/O error")]
Io(#[source] std::io::Error),
}

#[derive(Debug, Error)]
pub enum DiffCheckoutError {
#[error("Failed to write directories to diff: {0}")]
#[error("Failed to write directories to diff")]
Checkout(#[from] CheckoutError),
#[error("Error setting up temporary directory: {0}")]
#[error("Error setting up temporary directory")]
SetUpDir(#[source] std::io::Error),
#[error(transparent)]
TreeState(#[from] TreeStateError),
Expand Down
4 changes: 2 additions & 2 deletions cli/src/merge_tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub enum DiffEditError {
ExternalTool(#[from] ExternalToolError),
#[error(transparent)]
DiffCheckoutError(#[from] DiffCheckoutError),
#[error("Failed to snapshot changes: {0}")]
#[error("Failed to snapshot changes")]
Snapshot(#[from] SnapshotError),
#[error(transparent)]
Config(#[from] config::ConfigError),
Expand Down Expand Up @@ -81,7 +81,7 @@ pub enum ConflictResolveError {
to see the exact invocation)."
)]
EmptyOrUnchanged,
#[error("Backend error: {0}")]
#[error("Backend error")]
Backend(#[from] jj_lib::backend::BackendError),
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,25 @@ pub enum BackendError {
object_type: String,
hash: String,
},
#[error("Invalid UTF-8 for object {hash} of type {object_type}: {source}")]
#[error("Invalid UTF-8 for object {hash} of type {object_type}")]
InvalidUtf8 {
object_type: String,
hash: String,
source: std::str::Utf8Error,
},
#[error("Object {hash} of type {object_type} not found: {source}")]
#[error("Object {hash} of type {object_type} not found")]
ObjectNotFound {
object_type: String,
hash: String,
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("Error when reading object {hash} of type {object_type}: {source}")]
#[error("Error when reading object {hash} of type {object_type}")]
ReadObject {
object_type: String,
hash: String,
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("Could not write object of type {object_type}: {source}")]
#[error("Could not write object of type {object_type}")]
WriteObject {
object_type: &'static str,
source: Box<dyn std::error::Error + Send + Sync>,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/default_index/readonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::store::Store;

/// Error while loading index segment file.
#[derive(Debug, Error)]
#[error("Failed to load commit index file '{name}': {error}")]
#[error("Failed to load commit index file '{name}'")]
pub struct ReadonlyIndexLoadError {
/// Index file name.
pub name: String,
Expand Down
10 changes: 5 additions & 5 deletions lib/src/default_index/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const SEGMENT_FILE_NAME_LENGTH: usize = 64 * 2;

/// Error that may occur during `DefaultIndexStore` initialization.
#[derive(Debug, Error)]
#[error("Failed to initialize index store: {0}")]
#[error("Failed to initialize index store")]
pub struct DefaultIndexStoreInitError(#[from] pub PathError);

impl From<DefaultIndexStoreInitError> for BackendInitError {
Expand All @@ -56,20 +56,20 @@ impl From<DefaultIndexStoreInitError> for BackendInitError {
#[derive(Debug, Error)]
pub enum DefaultIndexStoreError {
#[error(
"Failed to associate commit index file with an operation {op_id}: {source}",
"Failed to associate commit index file with an operation {op_id}",
op_id = op_id.hex()
)]
AssociateIndex {
op_id: OperationId,
source: io::Error,
},
#[error("Failed to load associated commit index file name: {0}")]
#[error("Failed to load associated commit index file name")]
LoadAssociation(#[source] io::Error),
#[error(transparent)]
LoadIndex(ReadonlyIndexLoadError),
#[error("Failed to write commit index file: {0}")]
#[error("Failed to write commit index file")]
SaveIndex(#[source] io::Error),
#[error("Failed to index commits at operation {op_id}: {source}", op_id = op_id.hex())]
#[error("Failed to index commits at operation {op_id}", op_id = op_id.hex())]
IndexCommits {
op_id: OperationId,
source: BackendError,
Expand Down
16 changes: 8 additions & 8 deletions lib/src/fsmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,17 @@ pub mod watchman {
#[allow(missing_docs)]
#[derive(Debug, Error)]
pub enum Error {
#[error("Could not connect to Watchman: {0}")]
WatchmanConnectError(watchman_client::Error),
#[error("Could not connect to Watchman")]
WatchmanConnectError(#[source] watchman_client::Error),

#[error("Could not canonicalize working copy root path: {0}")]
CanonicalizeRootError(std::io::Error),
#[error("Could not canonicalize working copy root path")]
CanonicalizeRootError(#[source] std::io::Error),

#[error("Watchman failed to resolve the working copy root path: {0}")]
ResolveRootError(watchman_client::Error),
#[error("Watchman failed to resolve the working copy root path")]
ResolveRootError(#[source] watchman_client::Error),

#[error("Failed to query Watchman: {0}")]
WatchmanQueryError(watchman_client::Error),
#[error("Failed to query Watchman")]
WatchmanQueryError(#[source] watchman_client::Error),
}

/// Handle to the underlying Watchman instance.
Expand Down
20 changes: 10 additions & 10 deletions lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ fn resolve_git_ref_to_commit_id(

#[derive(Error, Debug)]
pub enum GitImportError {
#[error("Failed to read Git HEAD target commit {id}: {err}", id=id.hex())]
#[error("Failed to read Git HEAD target commit {id}", id=id.hex())]
MissingHeadTarget {
id: CommitId,
#[source]
err: BackendError,
},
#[error("Ancestor of Git ref {ref_name} is missing: {err}")]
#[error("Ancestor of Git ref {ref_name} is missing")]
MissingRefAncestor {
ref_name: String,
#[source]
Expand All @@ -186,9 +186,9 @@ pub enum GitImportError {
name = REMOTE_NAME_FOR_LOCAL_GIT_REPO
)]
RemoteReservedForLocalGitRepo,
#[error("Unexpected backend error when importing refs: {0}")]
#[error("Unexpected backend error when importing refs")]
InternalBackend(#[source] BackendError),
#[error("Unexpected git error when importing refs: {0}")]
#[error("Unexpected git error when importing refs")]
InternalGitError(#[source] Box<dyn std::error::Error + Send + Sync>),
#[error("The repo is not backed by a Git repo")]
UnexpectedBackend,
Expand Down Expand Up @@ -550,7 +550,7 @@ pub fn import_head(mut_repo: &mut MutableRepo) -> Result<(), GitImportError> {

#[derive(Error, Debug)]
pub enum GitExportError {
#[error("Git error: {0}")]
#[error("Git error")]
InternalGitError(#[source] Box<dyn std::error::Error + Send + Sync>),
#[error("The repo is not backed by a Git repo")]
UnexpectedBackend,
Expand Down Expand Up @@ -1081,10 +1081,10 @@ pub enum GitFetchError {
chars = INVALID_REFSPEC_CHARS.iter().join("`, `")
)]
InvalidBranchPattern,
#[error("Failed to import Git refs: {0}")]
#[error("Failed to import Git refs")]
GitImportError(#[from] GitImportError),
// TODO: I'm sure there are other errors possible, such as transport-level errors.
#[error("Unexpected git error when fetching: {0}")]
#[error("Unexpected git error when fetching")]
InternalGitError(#[from] git2::Error),
}

Expand Down Expand Up @@ -1196,7 +1196,7 @@ pub enum GitPushError {
RefUpdateRejected(Vec<String>),
// TODO: I'm sure there are other errors possible, such as transport-level errors,
// and errors caused by the remote rejecting the push.
#[error("Unexpected git error when pushing: {0}")]
#[error("Unexpected git error when pushing")]
InternalGitError(#[from] git2::Error),
}

Expand Down Expand Up @@ -1480,9 +1480,9 @@ pub struct SubmoduleConfig {

#[derive(Error, Debug)]
pub enum GitConfigParseError {
#[error("Unexpected io error when parsing config: {0}")]
#[error("Unexpected io error when parsing config")]
IoError(#[from] std::io::Error),
#[error("Unexpected git error when parsing config: {0}")]
#[error("Unexpected git error when parsing config")]
InternalGitError(#[from] git2::Error),
}

Expand Down
12 changes: 6 additions & 6 deletions lib/src/git_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ const CONFLICT_SUFFIX: &str = ".jjconflict";

#[derive(Debug, Error)]
pub enum GitBackendInitError {
#[error("Failed to initialize git repository: {0}")]
#[error("Failed to initialize git repository")]
InitRepository(#[source] gix::init::Error),
#[error("Failed to open git repository: {0}")]
#[error("Failed to open git repository")]
OpenRepository(#[source] gix::open::Error),
#[error(transparent)]
Path(PathError),
Expand All @@ -72,7 +72,7 @@ impl From<Box<GitBackendInitError>> for BackendInitError {

#[derive(Debug, Error)]
pub enum GitBackendLoadError {
#[error("Failed to open git repository: {0}")]
#[error("Failed to open git repository")]
OpenRepository(#[source] gix::open::Error),
#[error(transparent)]
Path(PathError),
Expand All @@ -87,9 +87,9 @@ impl From<Box<GitBackendLoadError>> for BackendLoadError {
/// `GitBackend`-specific error that may occur after the backend is loaded.
#[derive(Debug, Error)]
pub enum GitBackendError {
#[error("Failed to read non-git metadata: {0}")]
#[error("Failed to read non-git metadata")]
ReadMetadata(#[source] TableStoreError),
#[error("Failed to write non-git metadata: {0}")]
#[error("Failed to write non-git metadata")]
WriteMetadata(#[source] TableStoreError),
}

Expand All @@ -101,7 +101,7 @@ impl From<GitBackendError> for BackendError {

#[derive(Debug, Error)]
pub enum GitGcError {
#[error("Failed to run git gc command: {0}")]
#[error("Failed to run git gc command")]
GcCommand(#[source] std::io::Error),
#[error("git gc command exited with an error: {0}")]
GcCommandErrorStatus(ExitStatus),
Expand Down
12 changes: 6 additions & 6 deletions lib/src/local_working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,28 +477,28 @@ struct DirectoryToVisit<'a> {

#[derive(Debug, Error)]
pub enum TreeStateError {
#[error("Reading tree state from {path}: {source}")]
#[error("Reading tree state from {path}")]
ReadTreeState {
path: PathBuf,
source: std::io::Error,
},
#[error("Decoding tree state from {path}: {source}")]
#[error("Decoding tree state from {path}")]
DecodeTreeState {
path: PathBuf,
source: prost::DecodeError,
},
#[error("Writing tree state to temporary file {path}: {source}")]
#[error("Writing tree state to temporary file {path}")]
WriteTreeState {
path: PathBuf,
source: std::io::Error,
},
#[error("Persisting tree state to file {path}: {source}")]
#[error("Persisting tree state to file {path}")]
PersistTreeState {
path: PathBuf,
source: std::io::Error,
},
#[error("Filesystem monitor error: {0}")]
Fsmonitor(Box<dyn Error + Send + Sync>),
#[error("Filesystem monitor error")]
Fsmonitor(#[source] Box<dyn Error + Send + Sync>),
}

impl TreeState {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/op_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,19 +411,19 @@ content_hash! {

#[derive(Debug, Error)]
pub enum OpStoreError {
#[error("Object {hash} of type {object_type} not found: {source}")]
#[error("Object {hash} of type {object_type} not found")]
ObjectNotFound {
object_type: String,
hash: String,
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("Error when reading object {hash} of type {object_type}: {source}")]
#[error("Error when reading object {hash} of type {object_type}")]
ReadObject {
object_type: String,
hash: String,
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("Could not write object of type {object_type}: {source}")]
#[error("Could not write object of type {object_type}")]
WriteObject {
object_type: &'static str,
source: Box<dyn std::error::Error + Send + Sync>,
Expand Down
8 changes: 4 additions & 4 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ pub enum StoreLoadError {
store: &'static str,
store_type: String,
},
#[error("Failed to read {store} backend type: {source}")]
#[error("Failed to read {store} backend type")]
ReadError {
store: &'static str,
source: PathError,
Expand Down Expand Up @@ -1398,7 +1398,7 @@ pub struct RewriteRootCommit;
/// Error from attempts to edit a commit
#[derive(Debug, Error)]
pub enum EditCommitError {
#[error("Current working-copy commit not found: {0}")]
#[error("Current working-copy commit not found")]
WorkingCopyCommitNotFound(#[source] BackendError),
#[error("Cannot rewrite the root commit")]
RewriteRootCommit,
Expand All @@ -1407,9 +1407,9 @@ pub enum EditCommitError {
/// Error from attempts to check out a commit
#[derive(Debug, Error)]
pub enum CheckOutCommitError {
#[error("Failed to create new working-copy commit: {0}")]
#[error("Failed to create new working-copy commit")]
CreateCommit(#[from] BackendError),
#[error("Failed to edit commit: {0}")]
#[error("Failed to edit commit")]
EditCommit(#[from] EditCommitError),
}

Expand Down
Loading

0 comments on commit 77ceadb

Please sign in to comment.