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

Error cleanup #53

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open

Conversation

LastExceed
Copy link

@LastExceed LastExceed commented Aug 19, 2023

turns SDKResult<T> into a type alias for Result<T, WootingAnalogResult> to get rid of all the .0s and .into()s

since i am unable to get this project to compile (can't figure out how to setup cmake etc), this PR will inevitably have compile time errors, especially in the cases where .into() converted both the result type and the inner value at the same time (which is something you shouldn't be doing anyway). these errors should be fairly easy to fix, and i'm happy to help. i'd do it myself if i could

@simon-wh
Copy link
Member

simon-wh commented Oct 10, 2023

Hey, so I just got some capacity to try out these changes.

Overall, they look pretty good. Although, there is one significant problem right now blocking compilation, which you alluded to in your OP.

It mainly appears in
wooting-analog-common/src/lib.rs
and
wooting-analog-sdk/src/ffi.rs

The main problem is, that previously we used the From/Into traits to be able to cleanly convert e.g. SDKResult<u32> -> i32, to effectively return the u32 value if it's Ok or return the WootingAnalogResult error code in the < 0 space if it was an Err. We also have the inverse in the wooting-analog-wrapper side, where it's taking i32 and wants to change it into an SDKResult<u32>.

So we need some form of solution for this to get this wrapped up, as this was the strategy to bridge the error handling into the C FFI space (and then return from it in the wrapper). I'm not sure what the alternative solution would be, regardless, any change would break the C ABI which is kinda ruled out. Should we just make some helper functions to provide this functionality instead, as we can't implement the traits like they were done before? I think that's somewhat why I had the wrapper type for Result in the first place, so I could have these conversion traits applied to make various parts of the code simpler (although it did come at the cost of making a whole lot of the other code more annoying)

@simon-wh
Copy link
Member

simon-wh commented Oct 10, 2023

btw, you can skip the cmake stuff by just commenting out the contents of the main function in wooting-analog-sdk/build.rs. In general that stuff is pretty annoying and causes a lot of headaches, I should make it so that it isn't a hard dependency for regular building, as it is just for testing the plugin C ABI

@LastExceed
Copy link
Author

comment out build.rs

oh that was an easy fix haha

Should we just make some helper functions to provide this functionality instead, as we can't implement the traits like they were done before?

we could actually, but we shouldn't, as both source and target type are foreign. Helper functions are the way to go, I added 3 extension traits for this. its a bit boilerplate, but that's necessary to handle surrogate values properly

the code compiles now

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

Successfully merging this pull request may close these issues.

3 participants