From 77ceadbfd028b28be51ea4da0fb5551e840ba2dd Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 3 Feb 2024 16:38:03 +0900 Subject: [PATCH] cleanup: remove remaining ": {source}" from error message templates --- cli/src/merge_tools/builtin.rs | 8 ++++---- cli/src/merge_tools/external.rs | 15 ++++++--------- cli/src/merge_tools/mod.rs | 4 ++-- lib/src/backend.rs | 8 ++++---- lib/src/default_index/readonly.rs | 2 +- lib/src/default_index/store.rs | 10 +++++----- lib/src/fsmonitor.rs | 16 ++++++++-------- lib/src/git.rs | 20 ++++++++++---------- lib/src/git_backend.rs | 12 ++++++------ lib/src/local_working_copy.rs | 12 ++++++------ lib/src/op_store.rs | 6 +++--- lib/src/repo.rs | 8 ++++---- lib/src/revset.rs | 4 ++-- lib/src/signing.rs | 8 ++++---- lib/src/simple_op_store.rs | 2 +- lib/src/tree.rs | 2 +- lib/src/working_copy.rs | 21 +++++++++++---------- lib/src/workspace.rs | 2 +- 18 files changed, 79 insertions(+), 81 deletions(-) diff --git a/cli/src/merge_tools/builtin.rs b/cli/src/merge_tools/builtin.rs index 52bcfd6bb..b3b3fe307 100644 --- a/cli/src/merge_tools/builtin.rs +++ b/cli/src/merge_tools/builtin.rs @@ -18,11 +18,11 @@ 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, @@ -30,14 +30,14 @@ pub enum BuiltinToolError { }, #[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), } diff --git a/cli/src/merge_tools/external.rs b/cli/src/merge_tools/external.rs index 33c447eae..31f71c833 100644 --- a/cli/src/merge_tools/external.rs +++ b/cli/src/merge_tools/external.rs @@ -107,21 +107,18 @@ 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] @@ -129,15 +126,15 @@ pub enum ExternalToolError { }, #[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), diff --git a/cli/src/merge_tools/mod.rs b/cli/src/merge_tools/mod.rs index 07e10f7ef..6bbcfb471 100644 --- a/cli/src/merge_tools/mod.rs +++ b/cli/src/merge_tools/mod.rs @@ -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), @@ -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), } diff --git a/lib/src/backend.rs b/lib/src/backend.rs index ca5c0c1f1..76779804b 100644 --- a/lib/src/backend.rs +++ b/lib/src/backend.rs @@ -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, }, - #[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, }, - #[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, diff --git a/lib/src/default_index/readonly.rs b/lib/src/default_index/readonly.rs index 584317a99..3bca5639c 100644 --- a/lib/src/default_index/readonly.rs +++ b/lib/src/default_index/readonly.rs @@ -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, diff --git a/lib/src/default_index/store.rs b/lib/src/default_index/store.rs index f6ec39d40..155b9329c 100644 --- a/lib/src/default_index/store.rs +++ b/lib/src/default_index/store.rs @@ -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 for BackendInitError { @@ -56,20 +56,20 @@ impl From 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, diff --git a/lib/src/fsmonitor.rs b/lib/src/fsmonitor.rs index d87c492d3..38dfdd99e 100644 --- a/lib/src/fsmonitor.rs +++ b/lib/src/fsmonitor.rs @@ -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. diff --git a/lib/src/git.rs b/lib/src/git.rs index fc02536ca..ed7a29c71 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -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] @@ -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), #[error("The repo is not backed by a Git repo")] UnexpectedBackend, @@ -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), #[error("The repo is not backed by a Git repo")] UnexpectedBackend, @@ -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), } @@ -1196,7 +1196,7 @@ pub enum GitPushError { RefUpdateRejected(Vec), // 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), } @@ -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), } diff --git a/lib/src/git_backend.rs b/lib/src/git_backend.rs index a4adad159..a7918bc60 100644 --- a/lib/src/git_backend.rs +++ b/lib/src/git_backend.rs @@ -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), @@ -72,7 +72,7 @@ impl From> 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), @@ -87,9 +87,9 @@ impl From> 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), } @@ -101,7 +101,7 @@ impl From 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), diff --git a/lib/src/local_working_copy.rs b/lib/src/local_working_copy.rs index 70d286d14..689d136a4 100644 --- a/lib/src/local_working_copy.rs +++ b/lib/src/local_working_copy.rs @@ -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), + #[error("Filesystem monitor error")] + Fsmonitor(#[source] Box), } impl TreeState { diff --git a/lib/src/op_store.rs b/lib/src/op_store.rs index 49cd27cf0..569106563 100644 --- a/lib/src/op_store.rs +++ b/lib/src/op_store.rs @@ -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, }, - #[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, }, - #[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, diff --git a/lib/src/repo.rs b/lib/src/repo.rs index d70925b72..495277790 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -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, @@ -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, @@ -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), } diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 1144dde3b..6f152d25b 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -59,14 +59,14 @@ pub enum RevsetResolutionError { AmbiguousCommitIdPrefix(String), #[error("Change ID prefix \"{0}\" is ambiguous")] AmbiguousChangeIdPrefix(String), - #[error("Unexpected error from store: {0}")] + #[error("Unexpected error from store")] StoreError(#[source] BackendError), } /// Error occurred during revset evaluation. #[derive(Debug, Error)] pub enum RevsetEvaluationError { - #[error("Unexpected error from store: {0}")] + #[error("Unexpected error from store")] StoreError(#[source] BackendError), #[error("{0}")] Other(String), diff --git a/lib/src/signing.rs b/lib/src/signing.rs index 909bead04..17659e04f 100644 --- a/lib/src/signing.rs +++ b/lib/src/signing.rs @@ -95,8 +95,8 @@ pub enum SignError { #[error("Invalid signature")] InvalidSignatureFormat, /// A generic error from the backend impl. - #[error("Signing error: {0}")] - Backend(Box), + #[error("Signing error")] + Backend(#[source] Box), } /// A result type for the signing/verifying operations @@ -109,8 +109,8 @@ pub enum SignInitError { #[error("Unknown signing backend configured: {0}")] UnknownBackend(String), /// A generic error from the backend impl. - #[error("Failed to initialize signing: {0}")] - Backend(Box), + #[error("Failed to initialize signing")] + Backend(#[source] Box), } /// A enum that describes if a created/rewritten commit should be signed or not. diff --git a/lib/src/simple_op_store.rs b/lib/src/simple_op_store.rs index f0dd2fc6f..833c00b16 100644 --- a/lib/src/simple_op_store.rs +++ b/lib/src/simple_op_store.rs @@ -43,7 +43,7 @@ const OPERATION_ID_LENGTH: usize = 64; const VIEW_ID_LENGTH: usize = 64; #[derive(Debug, Error)] -#[error("Failed to read {kind} with ID {id}: {err}")] +#[error("Failed to read {kind} with ID {id}")] struct DecodeError { kind: &'static str, id: String, diff --git a/lib/src/tree.rs b/lib/src/tree.rs index 6dcc0540e..23690ff6a 100644 --- a/lib/src/tree.rs +++ b/lib/src/tree.rs @@ -41,7 +41,7 @@ pub enum TreeMergeError { source: std::io::Error, file_id: FileId, }, - #[error("Backend error: {0}")] + #[error("Backend error")] BackendError(#[from] BackendError), } diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index db8870ad7..59c772c1b 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -149,7 +149,7 @@ pub enum SnapshotError { target: PathBuf, }, /// Reading or writing from the commit backend failed. - #[error("Internal backend error: {0}")] + #[error("Internal backend error")] InternalBackendError(#[from] BackendError), /// A file was larger than the specified maximum file size for new /// (previously untracked) files. @@ -163,7 +163,7 @@ pub enum SnapshotError { max_size: HumanByteSize, }, /// Some other error happened while snapshotting the working copy. - #[error("{message}: {err}")] + #[error("{message}")] Other { /// Error message. message: String, @@ -233,7 +233,7 @@ pub struct CheckoutStats { pub enum CheckoutError { /// The current working-copy commit was deleted, maybe by an overly /// aggressive GC that happened while the current process was running. - #[error("Current working-copy commit not found: {source}")] + #[error("Current working-copy commit not found")] SourceNotFound { /// The underlying error. source: Box, @@ -243,10 +243,10 @@ pub enum CheckoutError { #[error("Concurrent checkout")] ConcurrentCheckout, /// Reading or writing from the commit backend failed. - #[error("Internal backend error: {0}")] + #[error("Internal backend error")] InternalBackendError(#[from] BackendError), /// Some other error happened while checking out the working copy. - #[error("{message}: {err}")] + #[error("{message}")] Other { /// Error message. message: String, @@ -261,31 +261,32 @@ pub enum CheckoutError { pub enum ResetError { /// The current working-copy commit was deleted, maybe by an overly /// aggressive GC that happened while the current process was running. - #[error("Current working-copy commit not found: {source}")] + #[error("Current working-copy commit not found")] SourceNotFound { /// The underlying error. source: Box, }, /// Reading or writing from the commit backend failed. - #[error("Internal error: {0}")] + #[error("Internal error")] InternalBackendError(#[from] BackendError), /// Some other error happened while checking out the working copy. - #[error("{message}: {err}")] + #[error("{message}")] Other { /// Error message. message: String, - #[source] /// The underlying error. + #[source] err: Box, }, } /// An error while reading the working copy state. #[derive(Debug, Error)] -#[error("{message}: {err}")] +#[error("{message}")] pub struct WorkingCopyStateError { /// Error message. pub message: String, /// The underlying error. + #[source] pub err: Box, } diff --git a/lib/src/workspace.rs b/lib/src/workspace.rs index 7fc65c8c5..c97ce22a8 100644 --- a/lib/src/workspace.rs +++ b/lib/src/workspace.rs @@ -69,7 +69,7 @@ pub enum WorkspaceLoadError { RepoDoesNotExist(PathBuf), #[error("There is no Jujutsu repo in {0}")] NoWorkspaceHere(PathBuf), - #[error("Cannot read the repo: {0}")] + #[error("Cannot read the repo")] StoreLoadError(#[from] StoreLoadError), #[error("Repo path could not be interpreted as Unicode text")] NonUnicodePath,