aerospike / aerospike-client-rust

Rust client for the Aerospike database
https://www.aerospike.com/
Other
82 stars 28 forks source link

make error type compatible with `anyhow::Error` #130

Open databasedav opened 1 year ago

databasedav commented 1 year ago

this provides more ergonomic error handling with ?

anyhow::Error

i currently get something like this from an aerospike_client.get(...)?

error[E0277]: `(dyn StdError + std::marker::Send + 'static)` cannot be shared between threads safely
  --> /home/....rs:73:6
   |
73 |     }?;
   |      ^ `(dyn StdError + std::marker::Send + 'static)` cannot be shared between threads safely
   |
   = help: the trait `Sync` is not implemented for `(dyn StdError + std::marker::Send + 'static)`
   = help: the following other types implement trait `FromResidual<R>`:
             <Result<T, F> as FromResidual<Result<Infallible, E>>>
             <Result<T, F> as FromResidual<Yeet<E>>>
   = note: required for `Unique<(dyn StdError + std::marker::Send + 'static)>` to implement `Sync`
   = note: required because it appears within the type `Box<dyn Error + Send>`
   = note: required because it appears within the type `Option<Box<dyn Error + Send>>`
   = note: required because it appears within the type `State`
   = note: required because it appears within the type `Error`
   = note: required for `anyhow::Error` to implement `From<aerospike_core::Error>`
   = note: required for `Result<std::option::Option<stream::Stream>, anyhow::Error>` to implement `FromResidual<Result<Infallible, aerospike_core::Error>>`
khaf commented 1 year ago

IIRC that's the fundamental issue with chain_error and why it was abandoned. We are going to move to thiserror to address this issue. I'm a bit tied elsewhere right now so I invite pull requests, but I'll do it myself in a week or two if no one volunteers.

databasedav commented 1 year ago

@khaf i can do the port to thiserror, is it ok if i target the async branch?

khaf commented 1 year ago

Yes, please do it. I'll review and merge it as soon as I can.

databasedav commented 1 year ago

@khaf getting these testing outputs (with warning omitted) on the async branch

$ cargo test --features rt-tokio
error[E0433]: failed to resolve: could not find `parse_macro_input` in `syn`
 --> aerospike-macro/src/lib.rs:8:22
  |
8 |     let input = syn::parse_macro_input!(input as syn::ItemFn);
  |                      ^^^^^^^^^^^^^^^^^ could not find `parse_macro_input` in `syn`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `aerospike-macro` due to previous error
$ cargo test --features rt-async-std
    Finished test [unoptimized + debuginfo] target(s) in 0.04s
     Running unittests src/lib.rs (target/debug/deps/aerospike-cc66c9d46ef2ad9d)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/client.rs (target/debug/deps/client-e52cb64243e30a29)

running 5 tests
test cluster_name - should panic ... ok
test close ... ok
test nodes ... ok
test get_node ... ok
test node_names ... ok

test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/lib.rs (target/debug/deps/lib-bc3f125cb9958adc)

running 30 tests
test src::batch::batch_get ... ok
test src::exp_op::exp_ops ... ok
test src::kv::connect ... ok
test src::hll::hll ... ok
test src::cdt_bitwise::cdt_bitwise ... ok
test src::serialization::serialize ... ok
test src::truncate::truncate ... ok
test src::cdt_list::cdt_list ... ok
test src::cdt_map::map_operations ... ok
test src::exp_bitwise::expression_bitwise ... FAILED
test src::exp_list::expression_list ... FAILED
test src::exp::expression_data_types ... FAILED
test src::exp_map::expression_map ... FAILED
test src::exp::expression_aero_5_6 ... FAILED
test src::exp::expression_condition ... FAILED
test src::exp::expression_commands ... FAILED
test src::exp_hll::expression_hll ... FAILED
test src::scan::scan_node ... FAILED
test src::scan::scan_single_consumer ... FAILED
test src::scan::scan_multi_consumer ... FAILED
test src::task::index_task_test ... ok
test src::query::query_node ... ok
test src::query::query_multi_consumer ... ok
test src::query::query_nobins ... ok
test src::query::query_single_consumer ... ok
test src::udf::execute_udf ... ok
test src::index::recreate_index - should panic ... FAILED
test src::task::register_task_test ... ok
test src::exp::expression_compare has been running for over 60 seconds
test src::exp::expression_rec_ops has been running for over 60 seconds

and then seems to hang forever

the top 3 src::exp... failures from above are giving me this sorta error

running 1 test
test src::exp::expression_data_types ... FAILED

failures:

---- src::exp::expression_data_types stdout ----
thread 'src::exp::expression_data_types' panicked at 'Error(Msg("Invalid size for buffer: 369098752"), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })', tests/src/exp.rs:777:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    src::exp::expression_data_types

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

this is all hitting a ce-6.3.0.2 docker container

i don't see any of these errors in the ci, but i also don't see these running here https://ci.appveyor.com/project/aerospike/aerospike-client-rust

any idea what's causing the invalid buffer size errors? just wanted to make the tests pass locally before replacing the errors

khaf commented 1 year ago

Yes I have fixed all of these with that last release, and will push the changes today if I get the time to fix a couple of tests due to server v6 default config changes.

khaf commented 1 year ago

Pushed.