diff --git a/server/feedback/src/main.rs b/server/feedback/src/main.rs index 40eae54b1..61bc4ace4 100644 --- a/server/feedback/src/main.rs +++ b/server/feedback/src/main.rs @@ -1,6 +1,7 @@ use actix_cors::Cors; use actix_governor::{GlobalKeyExtractor, Governor, GovernorConfigBuilder}; use std::collections::HashMap; +use std::error::Error; use crate::tokens::RecordedTokens; use actix_web::{get, middleware, web, App, HttpResponse, HttpServer}; @@ -12,6 +13,7 @@ mod github; mod post_feedback; mod proposed_edits; mod tokens; +type BoxedError=Box; const MAX_JSON_PAYLOAD: usize = 1024 * 1024; // 1 MB diff --git a/server/feedback/src/proposed_edits/image.rs b/server/feedback/src/proposed_edits/image.rs index 0213e2ec8..1c217800a 100644 --- a/server/feedback/src/proposed_edits/image.rs +++ b/server/feedback/src/proposed_edits/image.rs @@ -6,7 +6,6 @@ use serde::Deserialize; use serde::Serialize; use std::cmp::max; use std::collections::BTreeMap; -use std::error; use std::fs::File; use std::path::{Path, PathBuf}; @@ -57,7 +56,7 @@ impl Image { } } } - fn save_metadata(&self, key: &str, image_dir: &Path) -> Result<(), Box> { + fn save_metadata(&self, key: &str, image_dir: &Path) -> Result<(), crate::BoxedError> { let file = File::open(image_dir.join("img-sources.yaml"))?; let mut image_sources = serde_yaml::from_reader::<_, BTreeMap>>(file)?; @@ -80,7 +79,7 @@ impl Image { + 1; image_dir.join(format!("{key}_{next_free_slot}.webp")) } - fn save_content(&self, target: &Path) -> Result<(), Box> { + fn save_content(&self, target: &Path) -> Result<(), crate::BoxedError> { let bytes = BASE64_STANDARD.decode(&self.content)?; let image = image::load_from_memory(&bytes)?; diff --git a/server/feedback/src/proposed_edits/mod.rs b/server/feedback/src/proposed_edits/mod.rs index 84e8fc8d2..11ecd5298 100644 --- a/server/feedback/src/proposed_edits/mod.rs +++ b/server/feedback/src/proposed_edits/mod.rs @@ -36,7 +36,7 @@ impl EditRequest { async fn apply_changes_and_generate_description( &self, branch_name: &str, - ) -> Result> { + ) -> Result { let repo = TempRepo::clone_and_checkout(GIT_URL, branch_name).await?; let desc = repo.apply_and_gen_description(self); repo.commit(&desc.title).await?; diff --git a/server/feedback/src/proposed_edits/tmp_repo.rs b/server/feedback/src/proposed_edits/tmp_repo.rs index 8d149fb95..1f40ace00 100644 --- a/server/feedback/src/proposed_edits/tmp_repo.rs +++ b/server/feedback/src/proposed_edits/tmp_repo.rs @@ -1,6 +1,5 @@ use crate::proposed_edits::EditRequest; use log::{debug, info}; -use std::error; use tokio::process::Command; use crate::proposed_edits::discription::Description; @@ -13,7 +12,7 @@ impl TempRepo { pub async fn clone_and_checkout( url: &'static str, branch_name: &str, - ) -> Result> { + ) -> Result { let dir = tempfile::tempdir()?; info!("Cloning {url} into {dir:?}"); @@ -60,7 +59,7 @@ impl TempRepo { description } - pub async fn commit(&self, title: &str) -> Result<(), Box> { + pub async fn commit(&self, title: &str) -> Result<(), crate::BoxedError> { let out = Command::new("git") .current_dir(&self.dir) .arg("add") @@ -82,7 +81,7 @@ impl TempRepo { _ => Err(format!("git commit failed with output: {out:?}").into()), } } - pub async fn push(&self) -> Result<(), Box> { + pub async fn push(&self) -> Result<(), crate::BoxedError> { let out = Command::new("git") .current_dir(&self.dir) .arg("status") diff --git a/server/main-api/src/main.rs b/server/main-api/src/main.rs index dbd139235..0ef98346d 100644 --- a/server/main-api/src/main.rs +++ b/server/main-api/src/main.rs @@ -6,6 +6,7 @@ use sqlx::postgres::PgPoolOptions; use sqlx::prelude::*; use sqlx::PgPool; use std::collections::HashMap; +use std::error::Error; use structured_logger::async_json::new_writer; use structured_logger::Builder; @@ -52,7 +53,7 @@ fn connection_string() -> String { } #[tokio::main] -async fn main() -> Result<(), Box> { +async fn main() -> Result<(), crate::BoxedError> { Builder::with_level("info") .with_target_writer("*", new_writer(tokio::io::stdout())) .init(); diff --git a/server/main-api/src/maps/fetch_tile.rs b/server/main-api/src/maps/fetch_tile.rs index efb680cd8..573288e92 100644 --- a/server/main-api/src/maps/fetch_tile.rs +++ b/server/main-api/src/maps/fetch_tile.rs @@ -109,7 +109,7 @@ impl FetchTileTask { async fn download_map_image( &self, file: &std::path::PathBuf, - ) -> Result> { + ) -> Result { let url = self.get_tileserver_url(); let res = reqwest::get(&url).await?.bytes().await?; diff --git a/server/main-api/src/setup/database/alias.rs b/server/main-api/src/setup/database/alias.rs index a546d6240..c7117d6ea 100644 --- a/server/main-api/src/setup/database/alias.rs +++ b/server/main-api/src/setup/database/alias.rs @@ -104,7 +104,7 @@ impl Alias { pub(crate) async fn load_all_to_db( tx: &mut sqlx::Transaction<'_, sqlx::Postgres>, -) -> Result<(), Box> { +) -> Result<(), crate::BoxedError> { let cdn_url = std::env::var("CDN_URL").unwrap_or_else(|_| "https://nav.tum.de/cdn".to_string()); let raw_aliase = reqwest::get(format!("{cdn_url}/api_data.json")) .await? diff --git a/server/main-api/src/setup/database/data.rs b/server/main-api/src/setup/database/data.rs index f95a98ca0..3c9c91b75 100644 --- a/server/main-api/src/setup/database/data.rs +++ b/server/main-api/src/setup/database/data.rs @@ -149,7 +149,7 @@ impl DelocalisedValues { } pub(crate) async fn load_all_to_db( tx: &mut sqlx::Transaction<'_, sqlx::Postgres>, -) -> Result<(), Box> { +) -> Result<(), crate::BoxedError> { let start = Instant::now(); let cdn_url = std::env::var("CDN_URL").unwrap_or_else(|_| "https://nav.tum.de/cdn".to_string()); let tasks = reqwest::get(format!("{cdn_url}/api_data.json")) diff --git a/server/main-api/src/setup/database/mod.rs b/server/main-api/src/setup/database/mod.rs index e197fdb43..223b21c3d 100644 --- a/server/main-api/src/setup/database/mod.rs +++ b/server/main-api/src/setup/database/mod.rs @@ -3,7 +3,8 @@ mod data; use log::info; -pub(crate) async fn setup_database(pool: &sqlx::PgPool) -> Result<(), Box> { +pub(crate) async fn setup_database(pool: &sqlx::PgPool) -> Result<(), crate::BoxedError> { + info!("setting up the database"); sqlx::migrate!("./migrations").run(pool).await?; info!("migrations complete"); @@ -14,7 +15,7 @@ pub(crate) async fn setup_database(pool: &sqlx::PgPool) -> Result<(), Box, -) -> Result<(), Box> { +) -> Result<(), crate::BoxedError> { info!("deleting old data"); sqlx::query!("DELETE FROM aliases") .execute(&mut **tx) diff --git a/server/main-api/src/setup/meilisearch.rs b/server/main-api/src/setup/meilisearch.rs index f68d37a8a..c0dbeeda3 100644 --- a/server/main-api/src/setup/meilisearch.rs +++ b/server/main-api/src/setup/meilisearch.rs @@ -4,7 +4,6 @@ use meilisearch_sdk::tasks::Task; use meilisearch_sdk::Client; use serde_json::Value; use std::collections::HashMap; -use std::error::Error; use std::time::Duration; const TIMEOUT: Option = Some(Duration::from_secs(20)); @@ -44,7 +43,8 @@ async fn wait_for_healthy(client: &Client) { } } -pub(crate) async fn setup_meilisearch() -> Result<(), Box> { +pub(crate) async fn setup_meilisearch() -> Result<(), crate::BoxedError> { + info!("setting up meilisearch"); let start = std::time::Instant::now(); let ms_url = std::env::var("MIELI_URL").unwrap_or_else(|_| "http://localhost:7700".to_string()); info!("connecting to Meilisearch at {ms_url}", ms_url = ms_url);