diff --git a/blueprint/cli/src/bin/db.rs b/blueprint/cli/src/bin/db.rs index 90086e29..58aa8005 100644 --- a/blueprint/cli/src/bin/db.rs +++ b/blueprint/cli/src/bin/db.rs @@ -496,7 +496,9 @@ fn get_db_config(config: &DatabaseConfig) -> PgConnectOptions { async fn get_db_client(config: &DatabaseConfig) -> PgConnection { let db_config = get_db_config(config); - let connection: PgConnection = Connection::connect_with(&db_config).await.unwrap(); + let connection: PgConnection = Connection::connect_with(&db_config) + .await + .expect("Should be able to connect to the database!"); connection } @@ -504,7 +506,9 @@ async fn get_db_client(config: &DatabaseConfig) -> PgConnection { async fn get_root_db_client(config: &DatabaseConfig) -> PgConnection { let db_config = get_db_config(config); let root_db_config = db_config.clone().database("postgres"); - let connection: PgConnection = Connection::connect_with(&root_db_config).await.unwrap(); + let connection: PgConnection = Connection::connect_with(&root_db_config) + .await + .expect("Should be able to connect to the database!"); connection } diff --git a/blueprint/cli/src/bin/generate.rs b/blueprint/cli/src/bin/generate.rs index 7069b3f5..325f10d8 100644 --- a/blueprint/cli/src/bin/generate.rs +++ b/blueprint/cli/src/bin/generate.rs @@ -428,7 +428,7 @@ fn get_liquid_template(path: &str) -> Result { .context(format!("Failed to read blueprint {path}!"))?; let template = liquid::ParserBuilder::with_stdlib() .build() - .unwrap() + .context("Failed to build Liquid parser")? .parse(template_source) .context("Failed to parse blueprint as Liquid template")?; @@ -508,10 +508,15 @@ fn validate_fields(fields: &[String]) -> Result>, an return Err(anyhow!("Invalid field definition: {field}!")); } - let field_name = String::from(captures.get(1).unwrap().as_str()); + let field_name = String::from( + captures + .get(1) + .expect("Should be able to get the field name") + .as_str(), + ); let field_type = captures .get(2) - .unwrap() + .expect("Should be able to get the field type") .as_str() .replace("Bool", "bool") .replace("string", "String"); diff --git a/blueprint/db/src/test_helpers/mod.rs.liquid b/blueprint/db/src/test_helpers/mod.rs.liquid index 45fcdfa7..6a599c36 100644 --- a/blueprint/db/src/test_helpers/mod.rs.liquid +++ b/blueprint/db/src/test_helpers/mod.rs.liquid @@ -35,27 +35,41 @@ pub async fn teardown_db(db_pool: DbPool) { drop(db_pool); let root_db_config = db_config.clone().database("postgres"); - let mut connection: PgConnection = Connection::connect_with(&root_db_config).await.unwrap(); + let mut connection: PgConnection = Connection::connect_with(&root_db_config) + .await + .expect("Should be able to connect to Postgres database!"); - let test_db_name = db_config.get_database().unwrap(); + let test_db_name = db_config + .get_database() + .expect("Should be able to get the database name!"); let query = format!("DROP DATABASE IF EXISTS {test_db_name}"); - connection.execute(query.as_str()).await.unwrap(); + connection + .execute(query.as_str()) + .await + .unwrap_or_else(|_| panic!("Could not execute DROP DATABASE {test_db_name} query!")); } async fn prepare_db(config: &DatabaseConfig) -> DatabaseConfig { let db_config = parse_db_config(&config.url); - let db_name = db_config.get_database().unwrap(); + let db_name = db_config + .get_database() + .expect("Should be able to get the database name!"); let root_db_config = db_config.clone().database("postgres"); - let mut connection: PgConnection = Connection::connect_with(&root_db_config).await.unwrap(); + let mut connection: PgConnection = Connection::connect_with(&root_db_config) + .await + .expect("Should be able to connect to the Postgres database!"); let test_db_name = build_test_db_name(db_name); let query = format!("CREATE DATABASE {test_db_name} TEMPLATE {db_name}"); - connection.execute(query.as_str()).await.unwrap(); + connection + .execute(query.as_str()) + .await + .unwrap_or_else(|_| panic!("Could not execute CREATE DATABASE {test_db_name} query!")); - let regex = Regex::new(r"(.+)\/(.+$)").unwrap(); + let regex = Regex::new(r"(.+)/(.+$)").expect("Should be able to compile regex"); let test_db_url = regex.replace(&config.url, |caps: &Captures| { format!("{}/{}", &caps[1], test_db_name) }); diff --git a/blueprint/web/src/lib.rs b/blueprint/web/src/lib.rs index 26cc19bc..424dac99 100644 --- a/blueprint/web/src/lib.rs +++ b/blueprint/web/src/lib.rs @@ -54,7 +54,7 @@ pub async fn run() -> anyhow::Result<()> { pub fn init_tracing() { let filter = EnvFilter::try_from_default_env() .or_else(|_| EnvFilter::try_new("info")) - .unwrap(); + .expect("Should be able to parse RUST_LOG or construct default filter from info level"); tracing_subscriber::registry() .with(fmt::layer()) .with(filter) diff --git a/blueprint/web/src/test_helpers/mod.rs.liquid b/blueprint/web/src/test_helpers/mod.rs.liquid index b3990227..fde8ec6f 100644 --- a/blueprint/web/src/test_helpers/mod.rs.liquid +++ b/blueprint/web/src/test_helpers/mod.rs.liquid @@ -78,7 +78,10 @@ impl TestRequest { #[allow(unused)] #[must_use] pub fn header(mut self, name: HeaderName, value: &str) -> Self { - self.headers.insert(name, value.parse().unwrap()); + self.headers.insert( + name, + value.parse().expect("Should be abe to parse header value"), + ); self } @@ -112,9 +115,11 @@ impl TestRequest { request_builder = request_builder.method(&self.method); - let request = request_builder.body(self.body); + let request = request_builder + .body(self.body) + .expect("Should be able to build request"); - self.router.oneshot(request.unwrap()).await.unwrap() + self.router.oneshot(request).await.unwrap() } } @@ -222,7 +227,9 @@ pub struct DbTestContext { #[allow(unused)] pub async fn setup() -> DbTestContext { let init_config: OnceCell = OnceCell::new(); - let config = init_config.get_or_init(|| load_config(&Environment::Test).unwrap()); + let config = init_config.get_or_init(|| { + load_config(&Environment::Test).expect("Should be able to load Test environment config") + }); let test_db_pool = setup_db(&config.database).await; diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 787f891d..bbc6cc3c 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -239,8 +239,10 @@ mod tests { } fn read_buffer(buffer: std::io::BufWriter>) -> String { - let bytes = buffer.into_inner().unwrap(); + let bytes = buffer + .into_inner() + .expect("Should be able to flush the buffer!"); - String::from_utf8(bytes).unwrap() + String::from_utf8(bytes).expect("Should be able to convert the buffer to a string!") } }