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

implement set_root_key_id #44

Merged
merged 1 commit into from
Dec 11, 2023
Merged

Conversation

louisjmorgan
Copy link

@louisjmorgan louisjmorgan commented Dec 9, 2023

I've added the wasm bindings for set_root_key_id as well as a test to ensure it works.

Currently the errors aren't being handled as far as I can tell. I assume if you pass the native function a string instead of an int you get a type error, but in the current implementation it seems to set the root key id to 0.

I was unable to chain the error mapping method that most of the other bindings seem to be using:

#[wasm_bindgen(js_name = setRootKeyId)]
pub fn set_root_key_id(&mut self, root_key_id: u32) -> Result<(), JsValue> {
    self.0
        .set_root_key_id(root_key_id)
        .map_err(|e| serde_wasm_bindgen::to_value(&e).unwrap())
}

Would give the following compiler/rust analyzer error:

no method named `map_err` found for unit type `()` in the current scope
   method not found in `()`

I did make it work the following way:

#[wasm_bindgen(js_name = setRootKeyId)]
pub fn set_root_key_id(&mut self, root_key_id: u32) -> Result<(), JsValue> {
    Ok(self.0.set_root_key_id(root_key_id))
}

But I wasn't sure if this is redundant without an accompanying Err statement. I certainly couldn't see any other methods constructed this way. I assume the JsValue refers to the way that wasm-bindgen returns the rust errors to javascript, but I'm not sure exactly how to make that happen without the map_err method chain.

Having said that I'm probably just missing something very obvious, so let me know and I'll make the relevant change.

I also notice my javascript formatter config disagrees with yours, if you let me know exactly what you're using (some kind of global prettier config?) I will try to match it and avoid inconsistencies.

@louisjmorgan louisjmorgan changed the title implement set_root_key_id without error handling implement set_root_key_id Dec 9, 2023
@divarvel
Copy link
Collaborator

I was unable to chain the error mapping method that most of the other bindings seem to be using

set_root_key_id() cannot fail, so you don't need to return a Result, and it does not return any value, it just modifies the object on which it is called, so returning () is fine. The merge method on BlockBuilder is like this.

Copy link
Collaborator

@divarvel divarvel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@divarvel divarvel merged commit 73431c4 into biscuit-auth:main Dec 11, 2023
3 checks passed
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