Skip to content

Commit

Permalink
remove useless unwraps
Browse files Browse the repository at this point in the history
  • Loading branch information
irevoire committed Apr 14, 2024
1 parent aeed723 commit 741bf4e
Show file tree
Hide file tree
Showing 18 changed files with 192 additions and 181 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct Movie {
#[tokio::main(flavor = "current_thread")]
async fn main() {
// Create a client (without sending any request so that can't fail)
let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();

// An index is where the documents are stored.
let movies = client.index("movies");
Expand Down
2 changes: 1 addition & 1 deletion examples/cli-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::io::stdin;

// instantiate the client. load it once
lazy_static! {
static ref CLIENT: Client = Client::new("http://localhost:7700", Some("masterKey"));
static ref CLIENT: Client = Client::new("http://localhost:7700", Some("masterKey")).unwrap();
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use meilisearch_sdk::{client::Client, indexes::Index, settings::Settings};
// we need an async runtime
#[tokio::main(flavor = "current_thread")]
async fn main() {
let client: Client = Client::new("http://localhost:7700", Some("masterKey"));
let client: Client = Client::new("http://localhost:7700", Some("masterKey")).unwrap();

// We try to create an index called `movies` with a primary_key of `movie_id`.
let my_index: Index = client
Expand Down
2 changes: 1 addition & 1 deletion examples/web_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod document;
use crate::document::{display, Crate};

lazy_static! {
static ref CLIENT: Client = Client::new("http://localhost:7700", Some("masterKey"));
static ref CLIENT: Client = Client::new("http://localhost:7700", Some("masterKey")).unwrap();
}

struct Model {
Expand Down
2 changes: 1 addition & 1 deletion meilisearch-test-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn meilisearch_test(params: TokenStream, input: TokenStream) -> TokenStream
let meilisearch_api_key = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
));
outer_block.push(parse_quote!(
let client = Client::new(meilisearch_url, Some(meilisearch_api_key));
let client = Client::new(meilisearch_url, Some(meilisearch_api_key)).unwrap();
));
}

Expand Down
79 changes: 41 additions & 38 deletions src/client.rs

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<'a, Http: HttpClient> DocumentQuery<'a, Http> {
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// let index = client.index("document_query_with_fields");
/// let mut document_query = DocumentQuery::new(&index);
///
Expand All @@ -128,7 +128,7 @@ impl<'a, Http: HttpClient> DocumentQuery<'a, Http> {
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
/// #[derive(Debug, Serialize, Deserialize, PartialEq)]
/// struct MyObject {
Expand Down Expand Up @@ -220,7 +220,7 @@ impl<'a, Http: HttpClient> DocumentsQuery<'a, Http> {
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// let index = client.index("my_index");
///
/// let mut documents_query = DocumentsQuery::new(&index).with_offset(1);
Expand All @@ -240,7 +240,7 @@ impl<'a, Http: HttpClient> DocumentsQuery<'a, Http> {
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// let index = client.index("my_index");
///
/// let mut documents_query = DocumentsQuery::new(&index);
Expand All @@ -262,7 +262,7 @@ impl<'a, Http: HttpClient> DocumentsQuery<'a, Http> {
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// let index = client.index("my_index");
///
/// let mut documents_query = DocumentsQuery::new(&index);
Expand Down Expand Up @@ -293,7 +293,7 @@ impl<'a, Http: HttpClient> DocumentsQuery<'a, Http> {
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
/// # let index = client.create_index("documents_query_execute", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap();
/// #[derive(Debug, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -541,7 +541,7 @@ mod tests {
#[meilisearch_test]
async fn test_get_documents_with_error_hint() -> Result<(), Error> {
let meilisearch_url = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
let client = Client::new(format!("{meilisearch_url}/hello"), Some("masterKey"));
let client = Client::new(format!("{meilisearch_url}/hello"), Some("masterKey")).unwrap();
let index = client.index("test_get_documents_with_filter_wrong_ms_version");

let documents = DocumentsQuery::new(&index)
Expand Down
4 changes: 2 additions & 2 deletions src/dumps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
//! # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
//! #
//! # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
//! # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
//!
//! // Create a dump
//! let task_info = client.create_dump().await.unwrap();
Expand Down Expand Up @@ -59,7 +59,7 @@ impl<Http: HttpClient> Client<Http> {
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// #
/// let task_info = client.create_dump().await.unwrap();
///
Expand Down
6 changes: 6 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub enum Error {
/// Also check out: <https://github.com/meilisearch/Meilisearch/blob/main/meilisearch-error/src/lib.rs>
#[error(transparent)]
Meilisearch(#[from] MeilisearchError),

#[error(transparent)]
MeilisearchCommunication(#[from] MeilisearchCommunicationError),
/// The Meilisearch server returned an invalid JSON for a request.
Expand Down Expand Up @@ -50,13 +51,18 @@ pub enum Error {
// The library formatting the query parameters encountered an error.
#[error("Internal Error: could not parse the query parameters: {}", .0)]
Yaup(#[from] yaup::Error),

// The library validating the format of an uuid.
#[cfg(not(target_arch = "wasm32"))]
#[error("The uid of the token has bit an uuid4 format: {}", .0)]
Uuid(#[from] uuid::Error),

// Error thrown in case the version of the Uuid is not v4.
#[error("The uid provided to the token is not of version uuidv4")]
InvalidUuid4Version,

#[error(transparent)]
Other(Box<dyn std::error::Error + Send + Sync + 'static>),
}

#[derive(Debug, Clone, Deserialize, Error)]
Expand Down
6 changes: 3 additions & 3 deletions src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct ExperimentalFeaturesResult {
/// # use meilisearch_sdk::{client::Client, features::ExperimentalFeatures};
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// let mut features = ExperimentalFeatures::new(&client);
/// features.set_vector_store(true);
/// ```
Expand Down Expand Up @@ -57,7 +57,7 @@ impl<'a, Http: HttpClient> ExperimentalFeatures<'a, Http> {
/// # use meilisearch_sdk::{client::Client, features::ExperimentalFeatures};
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
/// let features = ExperimentalFeatures::new(&client);
/// features.get().await.unwrap();
Expand All @@ -82,7 +82,7 @@ impl<'a, Http: HttpClient> ExperimentalFeatures<'a, Http> {
/// # use meilisearch_sdk::{client::Client, features::ExperimentalFeatures};
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
/// let mut features = ExperimentalFeatures::new(&client);
/// features.set_vector_store(true);
Expand Down
Loading

0 comments on commit 741bf4e

Please sign in to comment.