this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Replacing log macros cuz I forgot they don't show until rocket configures them

Mar 3a4e5899 99813c7e

+59 -30
+11 -9
server/src/database.rs
··· 1 + use cynthia_con::{CynthiaColors, CynthiaStyles}; 1 2 use crate::errors::LuminaError::{self, ConfMissing}; 2 3 use r2d2::Pool; 3 4 use r2d2_sqlite; ··· 7 8 use tokio_postgres::{Client, Connection, Socket}; 8 9 9 10 pub(crate) async fn setup(config: crate::ServerConfig) -> Result<DbConn, LuminaError> { 11 + let warn = "[WARN]".color_bright_orange().style_bold(); 10 12 match (std::env::var("LUMINA_DB_TYPE") 11 13 .map_err(|_| ConfMissing("LUMINA_DB_TYPE".to_string())) 12 14 .unwrap_or(String::from("sqlite"))) ··· 52 54 .map_err(|_| ConfMissing("LUMINA_POSTGRES_DATABASE".to_string()))? 53 55 }); 54 56 pg_config.port(std::env::var("LUMINA_POSTGRES_PORT").unwrap_or_else(|_| { 55 - warn!("No Postgres database port provided under environment variable '_LUMINA_POSTGRES_PORT_'. Using default value '5432'."); 57 + eprintln!("{warn} No Postgres database port provided under environment variable '_LUMINA_POSTGRES_PORT_'. Using default value '5432'."); 56 58 "5432".to_string() 57 59 }).parse::<u16>().map_err(|_| { LuminaError::ConfInvalid("LUMINA_POSTGRES_PORT is not a valid integer number".to_string()) })?); 58 60 match std::env::var("LUMINA_POSTGRES_HOST") { ··· 60 62 pg_config.host(&val); 61 63 } 62 64 Err(_) => { 63 - warn!( 64 - "No Postgres database host provided under environment variable 'LUMINA_POSTGRES_HOST'. Using default value 'localhost'." 65 + eprintln!( 66 + "{warn} No Postgres database host provided under environment variable 'LUMINA_POSTGRES_HOST'. Using default value 'localhost'." 65 67 ); 66 68 pg_config.host("localhost"); 67 69 } ··· 71 73 pg_config.password(&val); 72 74 } 73 75 Err(_) => { 74 - info!( 75 - "No Postgres database password provided under environment variable 'LUMINA_POSTGRES_PASSWORD'. Trying passwordless authentication." 76 + println!( 77 + "{warn} No Postgres database password provided under environment variable 'LUMINA_POSTGRES_PASSWORD'. Trying passwordless authentication." 76 78 ); 77 79 } 78 80 }; ··· 126 128 Ok(DbConn::PgsqlConnection(conn.0)) 127 129 } 128 130 129 - _ => { 131 + c => { 132 + println!("{:?}", c); 130 133 Err(LuminaError::ConfInvalid( 131 - // "LUMINA_DB_TYPE does not contain a valid value, only 'sqlite' or 'postgres' are allowed.".to_string() 132 - "LUMINA_DB_TYPE does not contain a valid value, only 'postgres' is allowed." 133 - .to_string(), 134 + format!("LUMINA_DB_TYPE does not contain a valid value, only 'sqlite' or 'postgres' are allowed. Found: {}", c) 135 + 134 136 )) 135 137 } 136 138 }
-1
server/src/errors.rs
··· 1 1 use crate::postgres; 2 - use crate::sqlite; 3 2 use r2d2_sqlite::rusqlite; 4 3 pub(crate) enum LuminaError { 5 4 ConfMissing(String),
+48 -20
server/src/main.rs
··· 9 9 extern crate rocket; 10 10 use std::{ 11 11 net::{IpAddr, Ipv4Addr, Ipv6Addr}, 12 + process, 12 13 sync::Arc, 13 14 }; 14 15 use tokio::sync::Mutex; ··· 28 29 extern crate dotenv; 29 30 30 31 use crate::errors::LuminaError; 31 - use cynthia_con::CynthiaColors; 32 + use cynthia_con::{CynthiaColors, CynthiaStyles}; 32 33 use dotenv::dotenv; 33 34 34 35 fn config_get() -> Result<ServerConfig, LuminaError> { ··· 53 54 Ok(config) => { 54 55 let db = match database::setup(config.clone()).await { 55 56 Ok(db) => db, 56 - Err(LuminaError::ConfMissing(a)) => panic!( 57 - "Missing environment variable {}, which is required to continue. Please make sure it is set, or change other variables to make it redundant, if possible.", 58 - a.color_bright_orange() 59 - ), 57 + Err(LuminaError::ConfMissing(a)) => { 58 + eprintln!( 59 + "{} Missing environment variable {}, which is required to continue. Please make sure it is set, or change other variables to make it redundant, if possible.", 60 + "[ERROR]".color_error_red().style_bold(), 61 + a.color_bright_orange() 62 + ); 63 + process::exit(1); 64 + } 60 65 Err(LuminaError::ConfInvalid(a)) => { 61 - panic!("Invalid environment variable: {}", a.color_bright_orange()) 66 + eprintln!( 67 + "{} Invalid environment variable: {}", 68 + "[ERROR]".color_error_red().style_bold(), 69 + a.color_bright_orange() 70 + ); 71 + process::exit(1); 72 + } 73 + Err(LuminaError::Sqlite(a)) => { 74 + eprintln!("{} While opening sqlite database: {}", "[ERROR]".color_error_red().style_bold(),a); 75 + process::exit(1); 62 76 } 63 - Err(LuminaError::Sqlite(a)) => panic!("Error opening sqlite database: {}", a), 64 77 Err(LuminaError::Postgres(a)) => { 65 - panic!("Error connecting to postgres database: {}", a) 78 + eprintln!("{} While connecting to postgres database: {}", "[ERROR]".color_error_red().style_bold(), a); 79 + process::exit(1); 66 80 } 67 - Err(_) => panic!("Unknown error: could not setup database connection."), 81 + Err(_) => { 82 + eprintln!("{} Unknown error: could not setup database connection.", "[ERROR]".color_error_red().style_bold()); 83 + process::exit(1); 84 + } 68 85 }; 69 86 let appstate = AppState(Arc::from((config.clone(), Mutex::from(db)))); 70 - let mut def = rocket::Config::default(); 71 - def.port = config.port; 72 - def.address = config.host; 87 + let def = rocket::Config { 88 + port: config.port, 89 + address: config.host, 90 + ..rocket::Config::default() 91 + }; 73 92 let result = rocket::build() 74 93 .configure(def) 75 94 .mount( ··· 91 110 match result { 92 111 Ok(_) => {} 93 112 Err(LuminaError::RocketFaillure(e)) => { 94 - println!("Error starting server: {:?}", e); 113 + eprintln!("{} Error starting server: {:?}", "[ERROR]".color_error_red().style_bold(), e); 95 114 } 96 115 Err(_) => { 97 - println!("Unknown error starting server."); 116 + eprintln!("{} Unknown error starting server.", "[ERROR]".color_error_red().style_bold()); 98 117 } 99 118 } 100 119 } 101 - Err(LuminaError::ConfMissing(a)) => panic!( 102 - "Missing environment variable {}, which is required to continue. Please make sure it is set, or change other variables to make it redundant, if possible.", 103 - a.color_bright_orange() 104 - ), 120 + Err(LuminaError::ConfMissing(a)) => { 121 + eprintln!( 122 + "{} Missing environment variable {}, which is required to continue. Please make sure it is set, or change other variables to make it redundant, if possible.", 123 + "[ERROR]".color_error_red().style_bold() 124 + , 125 + a.color_bright_orange() 126 + ); 127 + process::exit(1); 128 + } 105 129 Err(LuminaError::ConfInvalid(a)) => { 106 - panic!("Invalid environment variable: {}", a.color_bright_orange()) 130 + eprintln!("{} Invalid environment variable: {}", "[ERROR]".color_error_red().style_bold(),a.color_bright_orange()); 131 + process::exit(1); 107 132 } 108 - Err(_) => panic!("Unknown error: could not setup server configuration."), 133 + Err(_) => { 134 + eprintln!("{} Unknown error: could not setup server configuration.", "[ERROR]".color_error_red().style_bold()); 135 + process::exit(1); 136 + } 109 137 }; 110 138 }