project-machine / puzzlefs

Apache License 2.0
380 stars 18 forks source link

Doesn't build with nightly toolchain #47

Closed ariel-miculas closed 1 year ago

ariel-miculas commented 1 year ago
$ make
cargo +nightly build
...
error[E0407]: method `backtrace` is not a member of trait `std::error::Error`
  --> format/src/error.rs:13:10
   |
13 | #[derive(Error)]
   |          ^^^^^ not a member of trait `std::error::Error`
   |
   = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: the feature `backtrace` has been stable since 1.65.0-nightly and no longer requires an attribute to enable
 --> format/src/lib.rs:1:12
  |
1 | #![feature(backtrace)]
  |            ^^^^^^^^^
  |
  = note: `#[warn(stable_features)]` on by default

error[E0599]: no method named `backtrace` found for reference `&dyn StdError` in the current scope
  --> format/src/error.rs:25:13
   |
25 |     #[error("fs error: {0}")]
   |             ^^^^^^^^^^^^^^^ method not found in `&dyn StdError`

error[E0599]: no method named `backtrace` found for reference `&dyn StdError` in the current scope
  --> format/src/error.rs:27:13
   |
27 |     #[error("deserialization error (cbor): {0}")]
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `&dyn StdError`

error[E0599]: no method named `backtrace` found for reference `&dyn StdError` in the current scope
  --> format/src/error.rs:29:13
   |
29 |     #[error("deserialization error (json): {0}")]
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `&dyn StdError`

error[E0599]: no method named `backtrace` found for reference `&WireFormatError` in the current scope
  --> format/src/error.rs:62:14
   |
62 |         self.backtrace()
   |              ^^^^^^^^^ method not found in `&WireFormatError`

warning: unused import: `std::error::Error`
 --> format/src/error.rs:5:5
  |
5 | use std::error::Error;
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

Some errors have detailed explanations: E0407, E0599.
For more information about an error, try `rustc --explain E0407`.
warning: `format` (lib) generated 2 warnings
error: could not compile `format` due to 5 previous errors; 2 warnings emitted
make: *** [Makefile:4: target/debug/puzzlefs] Error 101

std::backtrace::Backtrace was stabilized in 1.65.0 so we might be able to build puzzlefs on stable now.

Some links regarding error handling: https://nick.groenen.me/posts/rust-error-handling/ https://mmapped.blog/posts/12-rust-error-handling.html

ariel-miculas commented 1 year ago

Related: https://github.com/dtolnay/thiserror/issues/177

ariel-miculas commented 1 year ago

A way to display the stacktraces in tests would be to replace the unwrap() calls with proper error propagation:

diff --git a/Cargo.lock b/Cargo.lock
index 992cd9d..a74e5f1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -563,6 +563,7 @@ dependencies = [
 name = "oci"
 version = "0.1.0"
 dependencies = [
+ "anyhow",
  "compression",
  "format",
  "hex",
diff --git a/oci/Cargo.toml b/oci/Cargo.toml
index 6a505b6..68caa29 100644
--- a/oci/Cargo.toml
+++ b/oci/Cargo.toml
@@ -15,3 +15,6 @@ compression = { path = "../compression" }
 format = { path = "../format" }
 serde = { version = "^1.0.27", features = [ "derive" ] }
 serde_json = "*"
+
+[dev-dependencies]
+anyhow = "*"
diff --git a/oci/src/index.rs b/oci/src/index.rs
index 73447f1..c7efede 100644
--- a/oci/src/index.rs
+++ b/oci/src/index.rs
@@ -69,15 +69,16 @@ mod tests {
     use tempfile::tempdir;

     #[test]
-    fn test_can_open_new_index() {
-        let dir = tempdir().unwrap();
+    fn test_can_open_new_index() -> anyhow::Result<()> {
+        let dir = tempdir()?;
         let i = Index {
             version: 100,
             manifests: Vec::new(),
             annotations: HashMap::new(),
         };

-        i.write(&dir.path().join(PATH)).unwrap();
-        Index::open(&dir.path().join(PATH)).unwrap();
+        i.write(&dir.path().join(PATH))?;
+        Index::open(&dir.path().join(PATH))?;
+        Ok(())
     }
 }

This results in:

Stack backtrace:
   0: oci::index::Index::open
             at ./src/index.rs:46:17
   1: oci::index::tests::test_can_open_new_index
             at ./src/index.rs:81:9
   2: oci::index::tests::test_can_open_new_index::{{closure}}
             at ./src/index.rs:72:37
   3: core::ops::function::FnOnce::call_once
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/ops/function.rs:513:5
   4: core::ops::function::FnOnce::call_once
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/ops/function.rs:513:5
   5: test::__rust_begin_short_backtrace
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/test/src/lib.rs:637:18
   6: test::run_test::{{closure}}
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/test/src/lib.rs:628:30
   7: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/ops/function.rs:513:5
   8: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/alloc/src/boxed.rs:2000:9
   9: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/panic/unwind_safe.rs:271:9
  10: std::panicking::try::do_call
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/panicking.rs:483:40
  11: std::panicking::try
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/panicking.rs:447:19
  12: std::panic::catch_unwind
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/panic.rs:137:14
  13: test::run_test_in_process
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/test/src/lib.rs:660:27
  14: test::run_test::run_test_inner::{{closure}}
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/test/src/lib.rs:554:39
  15: test::run_test::run_test_inner::{{closure}}
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/test/src/lib.rs:581:37
  16: std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/sys_common/backtrace.rs:121:18
  17: std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/thread/mod.rs:551:17
  18: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/panic/unwind_safe.rs:271:9
  19: std::panicking::try::do_call
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/panicking.rs:483:40
  20: std::panicking::try
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/panicking.rs:447:19
  21: std::panic::catch_unwind
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/panic.rs:137:14
  22: std::thread::Builder::spawn_unchecked_::{{closure}}
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/thread/mod.rs:550:30
  23: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/ops/function.rs:513:5
  24: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/alloc/src/boxed.rs:2000:9
  25: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/alloc/src/boxed.rs:2000:9
  26: std::sys::unix::thread::Thread::new::thread_start
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/sys/unix/thread.rs:108:17
  27: <unknown>
  28: <unknown>
test index::tests::test_can_open_new_index ... FAILED

instead of

thread 'index::tests::test_can_open_new_index' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidImageSchema(100, Backtrace [{ fn: "oci::index::Index::open", file: "./src/index.rs", line: 46 }, { fn: "oci::index::tests::test_can_open_new_index", file: "./src/index.rs", line: 81 }, { fn: "oci::index::tests::test_can_open_new_index::{{closure}}", file: "./src/index.rs", line: 72 }, { fn: "core::ops::function::FnOnce::call_once", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/ops/function.rs", line: 513 }, { fn: "core::ops::function::FnOnce::call_once", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/ops/function.rs", line: 513 }, { fn: "test::__rust_begin_short_backtrace", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/test/src/lib.rs", line: 637 }, { fn: "test::run_test::{{closure}}", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/test/src/lib.rs", line: 628 }, { fn: "core::ops::function::FnOnce::call_once{{vtable.shim}}", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/ops/function.rs", line: 513 }, { fn: "<alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/alloc/src/boxed.rs", line: 2000 }, { fn: "<core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/panic/unwind_safe.rs", line: 271 }, { fn: "std::panicking::try::do_call", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/panicking.rs", line: 483 }, { fn: "std::panicking::try", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/panicking.rs", line: 447 }, { fn: "std::panic::catch_unwind", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/panic.rs", line: 137 }, { fn: "test::run_test_in_process", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/test/src/lib.rs", line: 660 }, { fn: "test::run_test::run_test_inner::{{closure}}", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/test/src/lib.rs", line: 554 }, { fn: "test::run_test::run_test_inner::{{closure}}", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/test/src/lib.rs", line: 581 }, { fn: "std::sys_common::backtrace::__rust_begin_short_backtrace", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/sys_common/backtrace.rs", line: 121 }, { fn: "std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/thread/mod.rs", line: 551 }, { fn: "<core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/panic/unwind_safe.rs", line: 271 }, { fn: "std::panicking::try::do_call", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/panicking.rs", line: 483 }, { fn: "std::panicking::try", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/panicking.rs", line: 447 }, { fn: "std::panic::catch_unwind", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/panic.rs", line: 137 }, { fn: "std::thread::Builder::spawn_unchecked_::{{closure}}", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/thread/mod.rs", line: 550 }, { fn: "core::ops::function::FnOnce::call_once{{vtable.shim}}", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/ops/function.rs", line: 513 }, { fn: "<alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/alloc/src/boxed.rs", line: 2000 }, { fn: "<alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/alloc/src/boxed.rs", line: 2000 }, { fn: "std::sys::unix::thread::Thread::new::thread_start", file: "/rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/sys/unix/thread.rs", line: 108 }])', oci/src/index.rs:81:45
stack backtrace:
   0: rust_begin_unwind
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/panicking.rs:65:14
   2: core::result::unwrap_failed
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/result.rs:1791:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/result.rs:1113:23
   4: oci::index::tests::test_can_open_new_index
             at ./src/index.rs:81:9
   5: oci::index::tests::test_can_open_new_index::{{closure}}
             at ./src/index.rs:72:34
   6: core::ops::function::FnOnce::call_once
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/ops/function.rs:513:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef/library/core/src/ops/function.rs:513:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
test index::tests::test_can_open_new_index ... FAILED

failures:

failures:
    index::tests::test_can_open_new_index

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 4 filtered out; finished in 0.01s

Relates to https://github.com/anuvu/puzzlefs/commit/8049c6a813aa934a246981b569bcb7eba739d957