Skip to content

Unwrap causes panic instead of handling the Result #575

@kingsleyh

Description

@kingsleyh

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)
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    maintenanceAnything related to maintenance (CI, tests, refactoring...)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions