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

Unwrap causes panic instead of handling the Result #575

Closed
kingsleyh opened this issue Apr 18, 2024 · 2 comments · Fixed by #603
Closed

Unwrap causes panic instead of handling the Result #575

kingsleyh opened this issue Apr 18, 2024 · 2 comments · Fixed by #603
Labels
maintenance Anything related to maintenance (CI, tests, refactoring...)

Comments

@kingsleyh
Copy link

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
Copy link
Author

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

@irevoire
Copy link
Member

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 irevoire added the maintenance Anything related to maintenance (CI, tests, refactoring...) label Apr 19, 2024
@irevoire irevoire reopened this Apr 19, 2024
@meili-bors meili-bors bot closed this as completed in 6c5f295 Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Anything related to maintenance (CI, tests, refactoring...)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants