meilisearch / meilisearch-rust

Rust wrapper for the Meilisearch API.

Home Page:https://www.meilisearch.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unwrap causes panic instead of handling the Result

kingsleyh opened this issue · 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)
    }

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

commented

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!