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

get_property: early return when property not found #2

Merged
merged 3 commits into from
Aug 30, 2023

Conversation

eguzki
Copy link

@eguzki eguzki commented Aug 22, 2023

When property is not found, the testing framework was returning Status::Ok with empty array.

Proxy-wasm-sdk library is reading that as correct return value and returning Ok(Some(Bytes)). The correct branch should be Status::NotFound => Ok(None), when the property is not found. So, fixing the return value from the testing framework.
Here https://github.com/proxy-wasm/proxy-wasm-rust-sdk/blob/v0.2.1/src/hostcalls.rs#L396-L422

pub fn get_property(path: Vec<&str>) -> Result<Option<Bytes>, Status> {
    let serialized_path = utils::serialize_property_path(path);
    let mut return_data: *mut u8 = null_mut();
    let mut return_size: usize = 0;
    unsafe {
        match proxy_get_property(
            serialized_path.as_ptr(),
            serialized_path.len(),
            &mut return_data,
            &mut return_size,
        ) {
            Status::Ok => {
                if !return_data.is_null() {
                    Ok(Some(Vec::from_raw_parts(
                        return_data,
                        return_size,
                        return_size,
                    )))
                } else {
                    Ok(None)
                }
            }
            Status::NotFound => Ok(None),
            status => panic!("unexpected status: {}", status as u32),
        }
    }
}

Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>
@eguzki eguzki requested a review from alexsnaps August 22, 2023 12:54
"[vm->host] proxy_get_property(path_data, path_size) -> NotFound, status: {:?}",
get_status()
);
assert_ne!(get_status(), ExpectStatus::Failed);
Copy link
Author

Choose a reason for hiding this comment

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

get_expect_get_property(path_raw) is setting status, so it must be asserted before returning.

@alexsnaps
Copy link
Member

👍 Nice. Sort of unrelated, but I'm thinking the SDK is wrong in not differentiating between a nil value to an existing property and a non existent prop... I was thinking of raising that with them, as the fn sig is Err = Status, it could return that information rather than discarding of it.

@eguzki
Copy link
Author

eguzki commented Aug 22, 2023

👍 Nice. Sort of unrelated, but I'm thinking the SDK is wrong in not differentiating between a nil value to an existing property and a non existent prop... I was thinking of raising that with them, as the fn sig is Err = Status, it could return that information rather than discarding of it.

I wonder what the meaning of nil is when you set a property and whether it has a use case or not.

@eguzki
Copy link
Author

eguzki commented Aug 22, 2023

tested in Kuadrant/wasm-shim#39

@eguzki eguzki marked this pull request as ready for review August 22, 2023 13:32
Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>
Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>
Copy link
Member

@alexsnaps alexsnaps left a comment

Choose a reason for hiding this comment

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

While String & Numbers are send as is, the byte[] is pretty much expected to be protobuf, so that there is no null and None as such is "there is no such property known"
That's my current understanding at least

@eguzki eguzki merged commit 29d5ac3 into kuadrant Aug 30, 2023
@eguzki eguzki deleted the fix-get-property-when-none branch August 30, 2023 14:09
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.

2 participants