-
Notifications
You must be signed in to change notification settings - Fork 277
Translate exceptions from C++ API into Rust Result
types.
#7511
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
Translate exceptions from C++ API into Rust Result
types.
#7511
Conversation
Codecov ReportBase: 78.50% // Head: 78.32% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## develop #7511 +/- ##
===========================================
- Coverage 78.50% 78.32% -0.18%
===========================================
Files 1663 1663
Lines 191297 191297
===========================================
- Hits 150174 149830 -344
- Misses 41123 41467 +344
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
src/libcprover-rust/src/lib.rs
Outdated
@@ -119,10 +131,18 @@ mod tests { | |||
let vect = ffi::translate_vector_of_string(vec); | |||
assert_eq!(vect.len(), 1); | |||
|
|||
client.load_model_from_files(vect); | |||
if let Err(_) = client.load_model_from_files(vect) { | |||
println!("Panicking: load_model_from_files_failed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this one panic, but not others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is experimental code that I failed to remove 🤦🏻♂️
Technically, when an assert!
macro fails, it calls panic!
- I wanted to simulate this behaviour manually (or at least approximate part of it) and then I forgot to remove it.
src/libcprover-rust/include/c_api.h
Outdated
} catch (const cprover_exception_baset &e) { | ||
fail(e.what()); | ||
} catch (const invariant_failedt &i) { | ||
fail(i.what()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we had preferred project style to use longer and clearer names than e
and i
.
src/libcprover-rust/src/lib.rs
Outdated
|
||
println!("Just before we print the messages"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover debug code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this was removed in the next commit.
let validation_msg = "Validating consistency of goto-model supplied to API session"; | ||
let msgs = ffi::get_messages(); | ||
print_response(msgs); | ||
let msgs_assert = translate_response_buffer(msgs).clone(); | ||
|
||
assert!(msgs_assert.contains(&String::from(validation_msg))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recognise this is in test code and so not that significant, but it would be much nicer if validate_goto_model()
actually returned a useful value instead of needing to string match over a collection of strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is very hard to do right now - the C++ API returns void
, and that's also because the function it's delegating to, validate_goto_model
in src/goto-programs/validate_goto_model.cpp:128
is also void
.
This will require some deep refactoring for these to behave this way.
The assertions I have added are along the lines of "Test for behaviour - not interface", which are just making sure that a side-effect of the action has been performed accurately.
Not terribly robust tests, but better than nothing - until at least a better interface presents itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood that this is test code and proper result structures are future work.
src/libcprover-rust/src/lib.rs
Outdated
let verification_msg = "VERIFICATION FAILED"; | ||
|
||
let msgs = ffi::get_messages(); | ||
print_response(msgs); | ||
let msgs_assert = translate_response_buffer(msgs).clone(); | ||
|
||
assert!(msgs_assert.contains(&String::from(verification_msg))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, better to get something useful back.
3aa2b65
to
fd6e3ec
Compare
fd6e3ec
to
99f0370
Compare
99f0370
to
f9da9dc
Compare
This PR is adding the capacity to the Rust API to translate exceptions from C++'s
end into Rust
Result
types that make handling of exceptions more robust andergonomic.
The last commit is not strictly related to the PR (it's a format using
cargo fmt
),but I hadn't run it against this project yet, so this is including it so that it
starts being formatted and consistent with
rust fmt
.