clucompany / cluFlock

Installation and subsequent safe removal of flock locks for data streams.
Apache License 2.0
7 stars 1 forks source link

Make compatible with anyhow #3

Closed davidanthoff closed 2 years ago

davidanthoff commented 2 years ago

I'm using the anyhow crate for error handling, and when I declare a function to use the anyhow::Result type, I can't get with_context and ? to work properly with functions from this crate here. For example:

SharedFlock::wait_lock(&lock_file)?

generates an error:

error[E0277]: the trait bound `FlockError<&std::fs::File>: StdError` is not satisfied
   --> src\config_file.rs:65:47
    |
65  |             SharedFlock::wait_lock(&lock_file)?
    |                                               ^ the trait `StdError` is not implemented for `FlockError<&std::fs::File>`
    |
    = note: required because of the requirements on the impl of `From<FlockError<&std::fs::File>>` for `anyhow::Error`
    = note: required because of the requirements on the impl of `FromResidual<Result<Infallible, FlockError<&std::fs::File>>>` for `Result<JuliaupConfig, anyhow::Error>`
note: required by `from_residual`
   --> C:\Users\david\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\ops\try_trait.rs:339:5
    |
339 |     fn from_residual(residual: R) -> Self;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0277`.

Not entirely clear to me what the problem is, maybe the error struct in cluFlock just needs to formally implement the std::Error trait? https://crates.io/crates/anyhow might have some info that someone with more Rust experience than me might be able to understand :)

Great package, thanks!

denisandroid commented 2 years ago

Thanks for writing, I'll try to fix it.

denisandroid commented 2 years ago

https://github.com/clucompany/cluFlock/commit/613f86bc193a61f86946547ca978b2f8abd7ea5a

davidanthoff commented 2 years ago

I just tried that version via cluFlock = { git = "https://github.com/clucompany/cluFlock" } in my Cargo.toml, now I get the following errors:

    Checking cluFlock v1.2.7 (https://github.com/clucompany/cluFlock#613f86bc)
error[E0432]: unresolved import `crate::os_release::r#dyn`
 --> C:\Users\david\.cargo\git\checkouts\cluflock-d61fcff256fb6a47\613f86b\src\os_release\windows.rs:9:24
  |
9 | use crate::os_release::r#dyn::BehOsRelease;
  |                        ^^^^^ could not find `r#dyn` in `os_release`

error[E0432]: unresolved import `crate::data::err::FlockFnError`
  --> C:\Users\david\.cargo\git\checkouts\cluflock-d61fcff256fb6a47\613f86b\src\os_release\windows.rs:10:5
   |
10 | use crate::data::err::FlockFnError;
   |     ^^^^^^^^^^^^^^^^^^------------
   |     |                 |
   |     |                 help: a similar name exists in the module: `FlockError`
   |     no `FlockFnError` in `data::err`

error[E0432]: unresolved import `crate::SafeUnlockFlock`
  --> C:\Users\david\.cargo\git\checkouts\cluflock-d61fcff256fb6a47\613f86b\src\os_release\windows.rs:12:5
   |
12 | use crate::SafeUnlockFlock;
   |     ^^^^^^^^^^^^^^^^^^^^^^ no `SafeUnlockFlock` in the root

error[E0432]: unresolved import `crate::FlockFnBuilder`
  --> C:\Users\david\.cargo\git\checkouts\cluflock-d61fcff256fb6a47\613f86b\src\os_release\windows.rs:20:5
   |
20 | use crate::FlockFnBuilder;
   |     ^^^^^^^^^^^^^^^^^^^^^ no `FlockFnBuilder` in the root

error[E0437]: type `UnlockResult` is not a member of trait `WaitFlockUnlock`
  --> C:\Users\david\.cargo\git\checkouts\cluflock-d61fcff256fb6a47\613f86b\src\os_release\windows.rs:42:2 
   |
42 |     type UnlockResult = ();
   |     ^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `WaitFlockUnlock`

error[E0433]: failed to resolve: use of undeclared type `I`
  --> C:\Users\david\.cargo\git\checkouts\cluflock-d61fcff256fb6a47\613f86b\src\os_release\windows.rs:97:12
   |
97 |         1 => Ok( I::ok(arg) ),
   |                  ^ use of undeclared type `I`

error[E0433]: failed to resolve: use of undeclared type `I`
  --> C:\Users\david\.cargo\git\checkouts\cluflock-d61fcff256fb6a47\613f86b\src\os_release\windows.rs:98:13
   |
98 |         _ => Err( I::err(arg, io::Error::last_os_error()) ),
   |                   ^ use of undeclared type `I`

error[E0412]: cannot find type `RawFd` in this scope
  --> C:\Users\david\.cargo\git\checkouts\cluflock-d61fcff256fb6a47\613f86b\src\os_release\windows.rs:93:36
   |
93 | fn flock<D: FlockElement<FilePtr = RawFd>, F: FnOnce(D) -> R, FE: FnOnce(D, std::io::Error) -> R, R>(arg: D, flag: DWORD, next: F, errf: ...
   |                                    ^^^^^ not found in this scope

And it goes on like that for quite a while.

The problem is probably use crate::os_release::r#dyn::BehOsRelease;, right?

denisandroid commented 2 years ago

https://github.com/clucompany/cluFlock/commit/0884dec2d45c0ef67c85d788d38419365a0931ba

davidanthoff commented 2 years ago

Great, much appreciated! Do you think you could release a new version to crates.io?

denisandroid commented 2 years ago

Yes, I will release it soon, you just need to test everything well before release.

denisandroid commented 2 years ago

So far, everything is stable at this stage, no one has written, the process has dragged on a bit.