From d4059b1720068610b6b412abae64d0e0ddba339a Mon Sep 17 00:00:00 2001 From: era Date: Sun, 28 May 2023 09:05:28 +0100 Subject: [PATCH 1/6] Improves the error message when crate is not found on default registry --- src/rustdoc_gen.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/rustdoc_gen.rs b/src/rustdoc_gen.rs index 57b4b891..f40d09cf 100644 --- a/src/rustdoc_gen.rs +++ b/src/rustdoc_gen.rs @@ -586,7 +586,7 @@ impl RustdocFromRegistry { let mut index = crates_index::Index::new_cargo_default()?; config.shell_status("Updating", "index")?; - while need_retry(index.update())? { + while need_retry(index.update()).map_err(human_readable_message)? { config.shell_status("Blocking", "waiting for lock on registry index")?; std::thread::sleep(REGISTRY_BACKOFF); } @@ -701,18 +701,35 @@ impl RustdocGenerator for RustdocFromRegistry { const REGISTRY_BACKOFF: std::time::Duration = std::time::Duration::from_secs(1); +/// Change the error message to be more human readable. +fn human_readable_message(err: crates_index::Error) -> anyhow::Error { + if let crates_index::Error::Git(ref err) = err { + if err.class() == git2::ErrorClass::Index && err.code() == git2::ErrorCode::NotFound { + return anyhow::anyhow!( + "{}. The registry is crates.io. \ + Crates published on a custom registry cannot be checked \ + using default settings, \ + see https://github.com/obi1kenobi/cargo-semver-checks/issues/166", + err + ); + } + } + + err.into() +} + /// Check if we need to retry retrieving the Index. -fn need_retry(res: Result<(), crates_index::Error>) -> anyhow::Result { +fn need_retry(res: Result<(), crates_index::Error>) -> Result { match res { Ok(()) => Ok(false), Err(crates_index::Error::Git(err)) => { if err.class() == git2::ErrorClass::Index && err.code() == git2::ErrorCode::Locked { Ok(true) } else { - Err(crates_index::Error::Git(err).into()) + Err(crates_index::Error::Git(err)) } } - Err(err) => Err(err.into()), + Err(err) => Err(err), } } From 79c6d89e0b076b06bba9a8e77b8fd9df3169ee68 Mon Sep 17 00:00:00 2001 From: era Date: Sun, 28 May 2023 10:00:46 +0100 Subject: [PATCH 2/6] Improves the error message when crate is not found on default registry --- src/rustdoc_gen.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/rustdoc_gen.rs b/src/rustdoc_gen.rs index f40d09cf..cc856012 100644 --- a/src/rustdoc_gen.rs +++ b/src/rustdoc_gen.rs @@ -661,7 +661,15 @@ impl RustdocGenerator for RustdocFromRegistry { let crate_ = self .index .crate_(crate_data.name) - .with_context(|| anyhow::format_err!("{} not found in registry", crate_data.name))?; + .with_context(|| { + anyhow::format_err!( + "{} not found in registry. The registry is crates.io. \ + Crates published on a custom registry cannot be checked \ + using default settings, \ + see https://github.com/obi1kenobi/cargo-semver-checks/issues/166", + crate_data.name + ) + })?; let base_version = if let Some(base) = self.version.as_ref() { base.to_string() From aa5a244448695812f6966db44678ab8b04a65548 Mon Sep 17 00:00:00 2001 From: era Date: Sun, 28 May 2023 10:01:53 +0100 Subject: [PATCH 3/6] reverts d4059b1720068610b6b412abae64d0e0ddba339a --- src/rustdoc_gen.rs | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/src/rustdoc_gen.rs b/src/rustdoc_gen.rs index cc856012..6b67ea47 100644 --- a/src/rustdoc_gen.rs +++ b/src/rustdoc_gen.rs @@ -586,7 +586,7 @@ impl RustdocFromRegistry { let mut index = crates_index::Index::new_cargo_default()?; config.shell_status("Updating", "index")?; - while need_retry(index.update()).map_err(human_readable_message)? { + while need_retry(index.update())? { config.shell_status("Blocking", "waiting for lock on registry index")?; std::thread::sleep(REGISTRY_BACKOFF); } @@ -709,35 +709,18 @@ impl RustdocGenerator for RustdocFromRegistry { const REGISTRY_BACKOFF: std::time::Duration = std::time::Duration::from_secs(1); -/// Change the error message to be more human readable. -fn human_readable_message(err: crates_index::Error) -> anyhow::Error { - if let crates_index::Error::Git(ref err) = err { - if err.class() == git2::ErrorClass::Index && err.code() == git2::ErrorCode::NotFound { - return anyhow::anyhow!( - "{}. The registry is crates.io. \ - Crates published on a custom registry cannot be checked \ - using default settings, \ - see https://github.com/obi1kenobi/cargo-semver-checks/issues/166", - err - ); - } - } - - err.into() -} - /// Check if we need to retry retrieving the Index. -fn need_retry(res: Result<(), crates_index::Error>) -> Result { +fn need_retry(res: Result<(), crates_index::Error>) -> anyhow::Result { match res { Ok(()) => Ok(false), Err(crates_index::Error::Git(err)) => { if err.class() == git2::ErrorClass::Index && err.code() == git2::ErrorCode::Locked { Ok(true) } else { - Err(crates_index::Error::Git(err)) + Err(crates_index::Error::Git(err).into()) } } - Err(err) => Err(err), + Err(err) => Err(err.into()), } } From 53edb30b9f2c5fe1d4b3fb3cdce0c130939ddd90 Mon Sep 17 00:00:00 2001 From: era Date: Sun, 28 May 2023 10:02:44 +0100 Subject: [PATCH 4/6] rust fmt --- src/rustdoc_gen.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/rustdoc_gen.rs b/src/rustdoc_gen.rs index 6b67ea47..578eb77e 100644 --- a/src/rustdoc_gen.rs +++ b/src/rustdoc_gen.rs @@ -658,18 +658,15 @@ impl RustdocGenerator for RustdocFromRegistry { rustdoc_cmd: &RustdocCommand, crate_data: CrateDataForRustdoc, ) -> anyhow::Result { - let crate_ = self - .index - .crate_(crate_data.name) - .with_context(|| { - anyhow::format_err!( - "{} not found in registry. The registry is crates.io. \ + let crate_ = self.index.crate_(crate_data.name).with_context(|| { + anyhow::format_err!( + "{} not found in registry. The registry is crates.io. \ Crates published on a custom registry cannot be checked \ using default settings, \ see https://github.com/obi1kenobi/cargo-semver-checks/issues/166", - crate_data.name - ) - })?; + crate_data.name + ) + })?; let base_version = if let Some(base) = self.version.as_ref() { base.to_string() From a54d1727b0056dbf4966ca8ed99ee6659ccf0163 Mon Sep 17 00:00:00 2001 From: era Date: Mon, 29 May 2023 08:02:04 +0100 Subject: [PATCH 5/6] reducing error message and trying to better frame the problem --- src/rustdoc_gen.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/rustdoc_gen.rs b/src/rustdoc_gen.rs index 578eb77e..0bf0e991 100644 --- a/src/rustdoc_gen.rs +++ b/src/rustdoc_gen.rs @@ -660,10 +660,9 @@ impl RustdocGenerator for RustdocFromRegistry { ) -> anyhow::Result { let crate_ = self.index.crate_(crate_data.name).with_context(|| { anyhow::format_err!( - "{} not found in registry. The registry is crates.io. \ - Crates published on a custom registry cannot be checked \ - using default settings, \ - see https://github.com/obi1kenobi/cargo-semver-checks/issues/166", + "{} not found in registry (crates.io). \ + For workarounds check \ + https://github.com/obi1kenobi/cargo-semver-checks#does-the-crate-im-checking-have-to-be-published-on-cratesio", crate_data.name ) })?; From 8cf16a03d410da4111d99b4e24232c61de4bd73d Mon Sep 17 00:00:00 2001 From: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> Date: Mon, 29 May 2023 17:55:27 -0400 Subject: [PATCH 6/6] Update src/rustdoc_gen.rs --- src/rustdoc_gen.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rustdoc_gen.rs b/src/rustdoc_gen.rs index 0bf0e991..641395bd 100644 --- a/src/rustdoc_gen.rs +++ b/src/rustdoc_gen.rs @@ -661,7 +661,7 @@ impl RustdocGenerator for RustdocFromRegistry { let crate_ = self.index.crate_(crate_data.name).with_context(|| { anyhow::format_err!( "{} not found in registry (crates.io). \ - For workarounds check \ + For workarounds check \ https://github.com/obi1kenobi/cargo-semver-checks#does-the-crate-im-checking-have-to-be-published-on-cratesio", crate_data.name )