Convert format macros to new format

This commit is contained in:
Lucien Cartier-Tilet 2023-01-17 01:52:31 +01:00
parent 19ba3a750b
commit 1eb31f8e1e
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
6 changed files with 32 additions and 50 deletions

View File

@ -22,7 +22,7 @@ impl APVariables {
user_id: &str,
) -> Result<bool> {
let client = reqwest::Client::new();
let url = format!("{}/users/{}/sessions", self.endpoint, user_id);
let url = format!("{}/users/{user_id}/sessions", self.endpoint);
let response = client
.get(url)
.header("X-Appwrite-Key", self.api_key.clone())

View File

@ -47,10 +47,7 @@ impl std::fmt::Display for DatabaseError {
impl IntoFieldError for DatabaseError {
fn into_field_error(self) -> juniper::FieldError<DefaultScalarValue> {
let short = self.short;
FieldError::new(
self.long,
graphql_value!({ "error": short }),
)
FieldError::new(self.long, graphql_value!({ "error": short }))
}
}
@ -88,7 +85,7 @@ impl Database {
{
self.conn.get().map_err(|e| {
DatabaseError::new(
format!("Failed to connect to database: {:?}", e),
format!("Failed to connect to database: {e:?}"),
"Database connection error",
)
})
@ -99,11 +96,11 @@ impl Database {
languages
.load::<Language>(&mut self.conn()?)
.map_err(|e| {
info!("Failed to retrieve languages from database: {:?}", e);
info!("Failed to retrieve languages from database: {e:?}");
})
.map_err(|e| {
DatabaseError::new(
format!("Failed to retrieve languages: {:?}", e),
format!("Failed to retrieve languages: {e:?}"),
"Failed to retrieve languages",
)
})
@ -113,7 +110,7 @@ impl Database {
use self::schema::users::dsl::users;
users.load::<User>(&mut self.conn()?).map_err(|e| {
DatabaseError::new(
format!("Failed to retrieve languages: {:?}", e),
format!("Failed to retrieve languages: {e:?}"),
"Failed to retrieve languages",
)
})
@ -125,13 +122,12 @@ impl Database {
) -> Result<Vec<Language>, DatabaseError> {
use self::schema::languages::dsl;
dsl::languages
.filter(dsl::name.ilike(format!("%{}%", query)))
.filter(dsl::name.ilike(format!("%{query}%")))
.load::<Language>(&mut self.conn()?)
.map_err(|e| {
DatabaseError::new(
format!(
"Failed to retrieve languages with query {}: {:?}",
query, e
"Failed to retrieve languages with query {query}: {e:?}"
),
"Failed to retrieve languages",
)
@ -141,13 +137,12 @@ impl Database {
pub fn find_user(&self, query: &str) -> Result<Vec<User>, DatabaseError> {
use self::schema::users::dsl;
dsl::users
.filter(dsl::username.ilike(format!("%{}%", query)))
.filter(dsl::username.ilike(format!("%{query}%")))
.load::<User>(&mut self.conn()?)
.map_err(|e| {
DatabaseError::new(
format!(
"Failed to retrieve users with query {}: {:?}",
query, e
"Failed to retrieve users with query {query}: {e:?}"
),
"Failed to retrieve languages",
)
@ -169,8 +164,7 @@ impl Database {
Err(Error::NotFound) => Ok(None),
Err(e) => Err(DatabaseError::new(
format!(
"Failed to find language {} belonging to {}: {:?}",
name, owner, e
"Failed to find language {name} belonging to {owner}: {e:?}"
),
"Database error",
)),
@ -183,10 +177,7 @@ impl Database {
Ok(val) => Ok(Some(val)),
Err(Error::NotFound) => Ok(None),
Err(e) => Err(DatabaseError::new(
format!(
"Failed to retrieve user {} from database: {:?}",
id, e
),
format!("Failed to retrieve user {id} from database: {e:?}"),
"Database Error",
)),
}
@ -202,14 +193,14 @@ impl Database {
match insert_into(users).values(user.clone()).execute(
&mut self.conn().map_err(|e| {
DatabaseError::new(
format!("Failed to connect to the database: {:?}", e),
format!("Failed to connect to the database: {e:?}"),
"Connection error",
)
})?,
) {
Ok(_) => Ok(user),
Err(e) => Err(DatabaseError {
long: format!("Failed to insert user {:?}: {:?}", user, e),
long: format!("Failed to insert user {user:?}: {e:?}"),
short: "Data insertion error".to_string(),
}),
}
@ -222,7 +213,7 @@ impl Database {
{
Ok(_) => Ok(()),
Err(e) => Err(DatabaseError::new(
format!("Failed to delete user {}: {:?}", id, e),
format!("Failed to delete user {id}: {e:?}"),
"User deletion error",
)),
}
@ -234,10 +225,7 @@ impl Database {
Ok(val) => Ok(Some(val)),
Err(Error::NotFound) => Ok(None),
Err(e) => Err(DatabaseError::new(
format!(
"Failed to retrieve word {} from database: {:?}",
id, e
),
format!("Failed to retrieve word {id} from database: {e:?}"),
"Database Error",
)),
}
@ -256,8 +244,7 @@ impl Database {
.map_err(|e| {
DatabaseError::new(
format!(
"Failed to retrieve word {} from language {}: {:?}",
word, language, e
"Failed to retrieve word {word} from language {language}: {e:?}"
),
"Failed to retrieve languages",
)
@ -272,14 +259,12 @@ impl Database {
use self::schema::words::dsl;
dsl::words
.filter(dsl::language.eq(language))
.filter(dsl::norm.ilike(format!("%{}%", query)))
.filter(dsl::norm.ilike(format!("%{query}%")))
.load::<Word>(&mut self.conn()?)
.map_err(|e| {
DatabaseError::new(
format!(
"Failed to retrieve words from language {} with query {}: {:?}",
language,
query, e
"Failed to retrieve words from language {language} with query {query}: {e:?}"
),
"Failed to retrieve languages",
)

View File

@ -147,8 +147,7 @@ impl Language {
.map_err(|e| {
DatabaseError::new(
format!(
"Failed to retrieve language translations: {:?}",
e
"Failed to retrieve language translations: {e:?}"
),
"Database reading failure",
)
@ -160,7 +159,7 @@ impl Language {
})
.collect::<Vec<Language>>()),
Err(e) => Err(DatabaseError::new(
format!("Failed to connect to the database: {:?}", e),
format!("Failed to connect to the database: {e:?}"),
"Database connection failure",
)
.into()),
@ -218,14 +217,14 @@ impl Language {
.map_err(|e| {
DatabaseError::new(
format!(
"Failed to retrieve owner {} of language {}: {:?}",
self.owner, self.name, e
"Failed to retrieve owner {} of language {}: {e:?}",
self.owner, self.name
),
"Database reading error",
)
})?),
Err(e) => Err(DatabaseError::new(
format!("Failed to connect to the database: {:?}", e),
format!("Failed to connect to the database: {e:?}"),
"Database connection failure",
)
.into()),

View File

@ -28,7 +28,7 @@ impl User {
use super::super::schema::{userfollows, users};
let conn = &mut context.db.conn().map_err(|e| {
DatabaseError::new(
format!("Failed to connect to database: {:?}", e),
format!("Failed to connect to database: {e:?}"),
"Database connection error",
)
})?;
@ -38,8 +38,7 @@ impl User {
.map_err(|e| {
DatabaseError::new(
format!(
"Failed to retrieve user follows from database: {:?}",
e
"Failed to retrieve user follows from database: {e:?}"
),
"Database reading error",
)
@ -52,9 +51,8 @@ impl User {
Ok(val) => Some(val),
Err(e) => {
let err = DatabaseError::new(
format!("Failed to retrieve user {} from database: {:?}",
f.following.clone(),
e),
format!("Failed to retrieve user {} from database: {e:?}",
f.following.clone()),
"Database reading error");
debug!("{}", err);
None

View File

@ -76,7 +76,7 @@ impl Word {
.load::<WordRelation>(conn)
.map_err(|e| {
DatabaseError::new(
format!("Failed to retrieve word relations: {:?}", e),
format!("Failed to retrieve word relations: {e:?}"),
"Database reading failed",
)
})?
@ -87,7 +87,7 @@ impl Word {
})
.collect::<Vec<Word>>()),
Err(e) => Err(DatabaseError::new(
format!("Failed to connect to the database: {:?}", e),
format!("Failed to connect to the database: {e:?}"),
"Database connection error",
)),
}

View File

@ -120,7 +120,7 @@ impl Query {
.find_word(uuid, query.as_str())
.map_err(Into::into),
Err(e) => Err(DatabaseError::new(
format!("Failed to convert {} to a UUID: {:?}", language, e),
format!("Failed to convert {language} to a UUID: {e:?}"),
"Conversion Error",
)
.into()),
@ -147,7 +147,7 @@ impl Query {
context.db.words(uuid, word.as_str()).map_err(Into::into)
}
Err(e) => Err(DatabaseError::new(
format!("Failed to convert {} to a UUID: {:?}", language, e),
format!("Failed to convert {language} to a UUID: {e:?}"),
"Conversion Error",
)
.into()),