Skip to content
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

Replace error strings with enums #417

Closed

Conversation

ariel-miculas
Copy link
Contributor

@ariel-miculas ariel-miculas commented Jun 23, 2023

This is useful in no alloc scenarios and in cases where String is not
available (such as the Linux kernel).

@ariel-miculas
Copy link
Contributor Author

Relates to #221

@ariel-miculas ariel-miculas force-pushed the error_string_to_enum branch from 86c2ad2 to 17c11bb Compare June 23, 2023 21:51
@ariel-miculas
Copy link
Contributor Author

Maybe I should add a conversion from the enum values to the error strings in https://github.com/capnproto/capnproto-rust/blob/6e421db3b13ead5e92cce68cff186a96492b7d1d/capnp-rpc/src/rpc.rs#L368C3-L368C3 since this test is failing

.contains("Message contains null capability pointer")

capnp/src/serialize.rs Outdated Show resolved Hide resolved
capnp/src/lib.rs Outdated Show resolved Hide resolved
capnp/src/schema_capnp.rs Outdated Show resolved Hide resolved
@dwrensha
Copy link
Member

Maybe I should add a conversion from the enum values to the error strings in https://github.com/capnproto/capnproto-rust/blob/6e421db3b13ead5e92cce68cff186a96492b7d1d/capnp-rpc/src/rpc.rs#L368C3-L368C3 since this test is failing

.contains("Message contains null capability pointer")

I think there should be a conversion from enum values to more verbose messages, and that it should live in an impl Display.

@dwrensha dwrensha added the breaking change requires version bump label Jun 24, 2023
@ariel-miculas ariel-miculas force-pushed the error_string_to_enum branch from 17c11bb to fb28071 Compare June 26, 2023 09:58
capnp/src/text.rs Outdated Show resolved Hide resolved
@ariel-miculas ariel-miculas force-pushed the error_string_to_enum branch from fb28071 to 46541fa Compare June 26, 2023 14:59
@ariel-miculas
Copy link
Contributor Author

I think we can remove "except for error message" from the documentation with this PR. Do you have additional technical comments related to the code?

@dwrensha
Copy link
Member

I think we can remove "except for error message" from the documentation with this PR.

Yep.

Do you have additional technical comments related to the code?

I think this is in pretty good shape. The main barrier to merging now is that it's a breaking change, so we'll need to bump to version 0.18. To minimize churn, it might be good to try to fit some other pending breaking changes (for example #380) in with that version bump. How time-sensitive is this change for you?

@ariel-miculas
Copy link
Contributor Author

How time-sensitive is this change for you?

I'm in no rush at all, I just wanted to finish with this PR. I'm still working on getting capnp to compile in the kernel, so I might open other PRs with #[cfg(feature = "alloc")] in places where allocations happen, it's proven to be quite tricky until now.

This is useful in `no alloc` scenarios and in cases where String is not
available (such as the Linux kernel).
@ariel-miculas ariel-miculas force-pushed the error_string_to_enum branch from 46541fa to 5414689 Compare June 27, 2023 16:20
@dwrensha
Copy link
Member

I might open other PRs with #[cfg(feature = "alloc")] in places where allocations happen, it's proven to be quite tricky until now.

Please feel free to add those changes to this PR, if it makes sense to do so.

This allows us to compile capnproto in no-alloc environments.
@ariel-miculas
Copy link
Contributor Author

I need some help with the remaining cargo clippy warnings:

❯ cargo clippy
warning: unsafe function's docs miss `# Safety` section
  --> capnp/src/private/arena.rs:43:5
   |
43 | /     unsafe fn check_offset(
44 | |         &self,
45 | |         segment_id: u32,
46 | |         start: *const u8,
47 | |         offset_in_words: i32,
48 | |     ) -> Result<*const u8>;
   | |___________________________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc
   = note: `#[warn(clippy::missing_safety_doc)]` on by default

warning: unsafe function's docs miss `# Safety` section
   --> capnp/src/private/layout.rs:162:5
    |
162 |     pub unsafe fn target(ptr: *const Self) -> *const u8 {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc

warning: unsafe function's docs miss `# Safety` section
    --> capnp/src/private/layout.rs:2918:5
     |
2918 |     pub unsafe fn get_root_unchecked<'b>(location: *const u8) -> PointerReader<'b> {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc

warning: unsafe function's docs miss `# Safety` section
    --> capnp/src/private/layout.rs:3959:5
     |
3959 | /     pub unsafe fn is_canonical(
3960 | |         &self,
3961 | |         read_head: &Cell<*const u8>,
3962 | |         reff: *const WirePointer,
3963 | |     ) -> Result<bool> {
     | |_____________________^
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc

warning: `capnp` (lib) generated 4 warnings
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s

@ariel-miculas ariel-miculas force-pushed the error_string_to_enum branch from 6e70f4c to 71eb2e4 Compare June 30, 2023 11:38
@dwrensha
Copy link
Member

dwrensha commented Jul 1, 2023

Do those clippy warnings also get reported on the master branch? If so, then cleaning them up can be considered be out-of-scope for this pull request.

@ariel-miculas
Copy link
Contributor Author

Do those clippy warnings also get reported on the master branch? If so, then cleaning them up can be considered be out-of-scope for this pull request.

Ok, I will open a subsequent PR for the clippy changes.

@ariel-miculas ariel-miculas force-pushed the error_string_to_enum branch from 71eb2e4 to 873a1b7 Compare July 2, 2023 15:03
@ariel-miculas
Copy link
Contributor Author

There are some formatting changes with the latest nightly version of rust, I included these changes as a separate commit, let me know if you would like to see them squashed in another commit, I'm not sure what the best practice is in this situation.

@dwrensha
Copy link
Member

dwrensha commented Jul 3, 2023

Rebased and merged in 13ccb48 087a0fe c410b05.

I'm going to aim for releasing v0.18 this week.

@dwrensha dwrensha closed this Jul 3, 2023
@dwrensha
Copy link
Member

dwrensha commented Jul 3, 2023

I enabled more code in 579b4f4, allowing run-time reflection to still work in the no-alloc case. After this change, examples/wasm-hello-world works with capnp in no-alloc mode.

@ariel-miculas
Copy link
Contributor Author

Kudos for this, I know it was very tedious work

@dwrensha dwrensha mentioned this pull request Jul 3, 2023
@ariel-miculas
Copy link
Contributor Author

Btw, here's my perl script I've used to (semi)automate the replacements (in case someone wants to do the same for the other error strings): https://gist.github.com/ariel-miculas/e114394eccda9563434c1ad5af19c797

@dwrensha
Copy link
Member

dwrensha commented Jul 5, 2023

I'm going to aim for releasing v0.18 this week.

I'm now thinking that the release will be at least a few weeks from now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change requires version bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants