Skip to content

replace deprecated failure library with anyhow and thiserror #1456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 16, 2021

Conversation

syphar
Copy link
Member

@syphar syphar commented Aug 1, 2021

remembering that the failure crate is deprecated I replaced it with the recommended replacements.

  • Partially also replacing Result<T, Error with anyhow::Result<T>
  • for now mapping the failures coming from rustwide.

Some code by the WIP branch by @Nemo157.

I'm happy to add any improvements.

@syphar syphar added the S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed label Aug 1, 2021
Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks cargo build --features consistency-check - can you fix that while you're at it?

If you could give an example of a backtrace after this change, that would be super helpful :)

@@ -289,125 +304,133 @@ impl RustwideBuilder {
}

let mut build_dir = self.workspace.build_dir(&format!("{}-{}", name, version));
build_dir.purge()?;
build_dir.purge().map_err(FailureError::compat)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an awful lot of FailureError::compat in this file - could we maybe return a failure::Error from build_package() so we only have to convert it once? Or does that break backtraces because they're not stable in std?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there I'm really not sure what's best, could be come tricky.

This probably would mean changing the return types for more methods on RustwideBuilder, which then means converting the errors each time when we call out of the class.

I'll try to play around with some boundaries and then see if something looks better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's hard no worries, this is fine as-is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

( there is a chance it's also just too much for my rust-skills, I saw parts of the approach in the branch by Nemo)

self.repository_stats_updater.load_repository(metadata)
self.repository_stats_updater
.load_repository(metadata)
.map_err(Into::into)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, why not return a failure::Result from load_repository?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's probably the problem with the partial migration without rustwide :)

in the end, I wanted most part migrated, that includes the repository stats :)

@jyn514 jyn514 added S-waiting-on-author Status: This PR is incomplete or needs to address review comments and removed S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed labels Aug 10, 2021
@syphar
Copy link
Member Author

syphar commented Aug 10, 2021

If you could give an example of a backtrace after this change, that would be super helpful :)

Simple example from running database migrate without a database:

Error: failed to create the database connection pool

Caused by:
    failed to create the database connection pool

Stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.61/src/backtrace/libunwind.rs:90:5
      backtrace::backtrace::trace_unsynchronized
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.61/src/backtrace/mod.rs:66:5
   1: backtrace::backtrace::trace
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.61/src/backtrace/mod.rs:53:14
   2: anyhow::backtrace::capture::Backtrace::create
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.42/src/backtrace.rs:216:13
   3: anyhow::backtrace::capture::Backtrace::capture
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.42/src/backtrace.rs:204:17
   4: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.42/src/error.rs:519:25
   5: <core::result::Result<T,F> as core::ops::try_trait::FromResidual<core::result::Result<core::convert::Infallible,E>>>::from_residual
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/result.rs:1675:27
   6: <cratesfyi::BinContext as docs_rs::context::Context>::pool::{{closure}}
             at ./src/bin/cratesfyi.rs:600:48
   7: once_cell::imp::OnceCell<T>::initialize::{{closure}}
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.7.2/src/imp_pl.rs:64:19
   8: once_cell::imp::initialize_inner
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.7.2/src/imp_pl.rs:122:12
   9: once_cell::imp::OnceCell<T>::initialize
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.7.2/src/imp_pl.rs:54:9
  10: once_cell::sync::OnceCell<T>::get_or_try_init
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.7.2/src/lib.rs:885:13
  11: <cratesfyi::BinContext as docs_rs::context::Context>::pool
             at ./src/bin/cratesfyi.rs:598:12
  12: cratesfyi::BinContext::conn
             at ./src/bin/cratesfyi.rs:552:12
  13: cratesfyi::DatabaseSubcommand::handle_args
             at ./src/bin/cratesfyi.rs:421:44
  14: cratesfyi::CommandLine::handle_args
             at ./src/bin/cratesfyi.rs:135:46
  15: cratesfyi::main
             at ./src/bin/cratesfyi.rs:22:23
  16: core::ops::function::FnOnce::call_once
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/ops/function.rs:227:5
  17: std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sys_common/backtrace.rs:125:18
  18: std::rt::lang_start::{{closure}}
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/rt.rs:49:18
  19: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/ops/function.rs:259:13
      std::panicking::try::do_call
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:401:40
      std::panicking::try
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:365:19
      std::panic::catch_unwind
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panic.rs:434:14
      std::rt::lang_start_internal
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/rt.rs:34:21
  20: std::rt::lang_start
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/rt.rs:48:5
  21: <unknown>
             at ./src/bin/cratesfyi.rs:563:10

another error triggered in rustwide (unknow docker image):

Error: failed to pull the sandbox image from the registry: command failed: exit status: 1

Caused by:
    failed to pull the sandbox image from the registry: command failed: exit status: 1

Caused by:
    command failed: exit status: 1

Stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.61/src/backtrace/libunwind.rs:90:5
      backtrace::backtrace::trace_unsynchronized
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.61/src/backtrace/mod.rs:66:5
   1: backtrace::backtrace::trace
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.61/src/backtrace/mod.rs:53:14
   2: anyhow::backtrace::capture::Backtrace::create
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.42/src/backtrace.rs:216:13
   3: anyhow::backtrace::capture::Backtrace::capture
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.42/src/backtrace.rs:204:17
   4: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
             at /Users/syphar/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.42/src/error.rs:519:25
   5: <core::result::Result<T,F> as core::ops::try_trait::FromResidual<core::result::Result<core::convert::Infallible,E>>>::from_residual
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/result.rs:1675:27
   6: docs_rs::docbuilder::rustwide_builder::RustwideBuilder::init
             at ./src/docbuilder/rustwide_builder.rs:60:62
   7: cratesfyi::BuildSubcommand::handle_args::{{closure}}
             at ./src/bin/cratesfyi.rs:295:31
   8: cratesfyi::BuildSubcommand::handle_args
             at ./src/bin/cratesfyi.rs:312:35
   9: cratesfyi::Build::handle_args
             at ./src/bin/cratesfyi.rs:245:9
  10: cratesfyi::CommandLine::handle_args
             at ./src/bin/cratesfyi.rs:117:35
  11: cratesfyi::main
             at ./src/bin/cratesfyi.rs:22:23
  12: core::ops::function::FnOnce::call_once
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/ops/function.rs:227:5
  13: std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sys_common/backtrace.rs:125:18
  14: std::rt::lang_start::{{closure}}
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/rt.rs:49:18
  15: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/ops/function.rs:259:13
      std::panicking::try::do_call
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:401:40
      std::panicking::try
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:365:19
      std::panic::catch_unwind
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panic.rs:434:14
      std::rt::lang_start_internal
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/rt.rs:34:21
  16: std::rt::lang_start
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/rt.rs:48:5
  17: <unknown>
             at ./src/bin/cratesfyi.rs:563:10

@syphar syphar added S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed and removed S-waiting-on-author Status: This PR is incomplete or needs to address review comments labels Aug 10, 2021
@jyn514 jyn514 merged commit b2eabd6 into rust-lang:master Aug 16, 2021
@syphar syphar deleted the anyhow branch August 16, 2021 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants