meilisearch-rust icon indicating copy to clipboard operation
meilisearch-rust copied to clipboard

Unwrap causes panic instead of handling the Result

Open kingsleyh opened this issue 1 year ago • 2 comments

When checking if an index exists this unwrap returns None and causes a panic.

Instead could handle this instead of using unwrap() so that it always returns the Result

file: meilisearch-sdk-0.25.0/src/client.rs:49:55

 fn parse_indexes_results_from_value(&self, value: &Value) -> Result<IndexesResults, Error> {
        let raw_indexes = value["results"].as_array().unwrap();

        let indexes_results = IndexesResults {
            limit: value["limit"].as_u64().unwrap() as u32,
            offset: value["offset"].as_u64().unwrap() as u32,
            total: value["total"].as_u64().unwrap() as u32,
            results: raw_indexes
                .iter()
                .map(|raw_index| Index::from_value(raw_index.clone(), self.clone()))
                .collect::<Result<_, _>>()?,
        };

        Ok(indexes_results)
    }

kingsleyh avatar Apr 18 '24 10:04 kingsleyh

I was using an old version of meilisearch - once I upgraded to the latest this went away

kingsleyh avatar Apr 18 '24 17:04 kingsleyh

Hey @kingsleyh

Thanks for your issue; you're right that this is not a bug if you use the correct version of the SDK with the right version of Meilisearch. But you're not wrong either; it shouldn't panic and return an error instead.

I'll reopen it but with the maintenance label instead of the bug one, thanks for the opening the issue!

irevoire avatar Apr 19 '24 16:04 irevoire