fix env errors not showing
Some checks failed
Build and Test / super-mario-maker (push) Failing after 6m27s
Build and Test / minecraft-wiiu (push) Failing after 9m27s
Build and Test / fast-racing-neo (push) Failing after 9m49s
Build and Test / wii-u-chat (push) Failing after 10m11s
Build and Test / friends (push) Failing after 10m11s
Build and Test / wii-sports-club (push) Failing after 10m11s
Build and Test / splatoon-testfire (push) Failing after 10m11s
Build and Test / mario-tennis (push) Failing after 10m12s
Build and Test / puyopuyo (push) Has been cancelled
Build and Test / sonic-transformed (push) Has been cancelled
Build and Test / splatoon (push) Has been cancelled

This commit is contained in:
Maple Nebel 2026-07-14 21:05:13 +02:00
commit 3351386c33
6 changed files with 31 additions and 11 deletions

1
Cargo.lock generated
View file

@ -2679,6 +2679,7 @@ dependencies = [
"rnex-rmc",
"rnex-util",
"sentry",
"thiserror",
"tokio",
"tracing",
"tracing-subscriber",

View file

@ -1,7 +1,7 @@
#![cfg(feature = "datastore")]
use std::env;
use rnex_server::{ConnectionInitData, RnexManager, RnexModule};
use rnex_server::{ConnectionInitData, EnvVarError, RnexManager, RnexModule, env_var};
use sqlx::PgPool;
use thiserror::Error;
@ -40,7 +40,7 @@ pub enum ModuleInitError {
#[error(transparent)]
Sqlx(#[from] sqlx::Error),
#[error(transparent)]
Env(#[from] env::VarError),
Env(#[from] EnvVarError),
}
impl RnexModule for DatastoreModule {
@ -51,12 +51,12 @@ impl RnexModule for DatastoreModule {
mod_holder: &rnex_server::ModuleHolder,
) -> Result<Self::Manager, Self::InitError> {
Ok(DatastoreManager {
db_pool: PgPool::connect(&env::var("RNEX_DATASTORE_DATABASE")?).await?,
db_pool: PgPool::connect(&env_var("RNEX_DATASTORE_DATABASE")?).await?,
s3_presigner: S3Presigner::new(
env::var("RNEX_DATASTORE_S3_ENDPOINT")?
env_var("RNEX_DATASTORE_S3_ENDPOINT")?
.trim_end_matches('/')
.to_string(),
env::var("RNEX_DATASTORE_S3_BUCKET")?,
env_var("RNEX_DATASTORE_S3_BUCKET")?,
),
})
}

View file

@ -3,7 +3,9 @@ use crate::friends_handler::{FriendsGuest, FriendsUser};
use nex_account::GUEST_PID;
use rnex_fpd_protos::RemoteFriendRemote;
use rnex_rmc::{RmcCallable, RmcPureRemoteObject};
use rnex_server::{ConnectionInitData, RnexManager, RnexModule, WeakPassthroughInitModule};
use rnex_server::{
ConnectionInitData, RnexManager, RnexModule, WeakPassthroughInitModule, env_var,
};
use rnex_util::PID;
use sqlx::PgPool;
use std::{
@ -97,7 +99,7 @@ impl RnexModule for FriendsModule {
) -> Result<Self::Manager, Self::InitError> {
Ok(FriendsManager {
users: Default::default(),
db: PgPool::connect(&env::var("RNEX_DATASTORE_DATABASE")?).await?,
db: PgPool::connect(&env_var("RNEX_DATASTORE_DATABASE")?).await?,
})
}
}

View file

@ -1,7 +1,7 @@
use std::env::{self, VarError};
use rnex_rmc::response::ErrorCode;
use rnex_server::{ConnectionInitData, RnexManager, RnexModule};
use rnex_server::{ConnectionInitData, RnexManager, RnexModule, env_var};
use std::str::FromStr;
use tracing::error;
@ -79,9 +79,9 @@ impl RnexModule for RankingModule {
_: &rnex_server::ModuleHolder,
) -> Result<Self::Manager, Self::InitError> {
Ok(RankingManager {
rnex_result_votes_get: env::var("RNEX_SPLATOON_RESULTS_VOTES_GET")?,
rnex_result_post: env::var("RNEX_SPLATOON_RESULTS_POST")?,
rnex_result_get: env::var("RNEX_SPLATOON_RESULTS_GET")?,
rnex_result_votes_get: env_var("RNEX_SPLATOON_RESULTS_VOTES_GET")?,
rnex_result_post: env_var("RNEX_SPLATOON_RESULTS_POST")?,
rnex_result_get: env_var("RNEX_SPLATOON_RESULTS_GET")?,
})
}
}

View file

@ -11,6 +11,7 @@ paste = "1.0.15"
rnex-rmc = { path = "../rnex-rmc" }
rnex-util = { path = "../rnex-util" }
sentry = { version = "0.48.4", features = ["tracing"] }
thiserror = "2.0.18"
tokio = { version = "1.52.3", features = ["net"] }
tracing = "0.1.44"
tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }

View file

@ -1,4 +1,5 @@
#![allow(async_fn_in_trait)]
use std::env::VarError;
use std::net::SocketAddr;
use std::sync::Weak;
use std::{
@ -19,6 +20,7 @@ pub use paste;
pub use rnex_rmc as rmc;
use rnex_rmc::{RmcCallable, RmcConnection, RmcSerialize, serialization::RmcSerialize, util::PID};
pub use rnex_util as util;
use thiserror::Error;
pub use tokio;
pub use tracing;
use tracing::{Instrument, Level, error, instrument, span};
@ -334,6 +336,20 @@ pub fn rnex_release() -> String {
)
}
#[derive(Error, Debug)]
#[error("error getting environment variable \"{1}\": {0}")]
pub struct EnvVarError(VarError, &'static str);
impl EnvVarError {
fn err_on(name: &'static str) -> impl Fn(VarError) -> Self {
move |e| Self(e, name)
}
}
pub fn env_var(name: &'static str) -> Result<String, EnvVarError> {
env::var(name).map_err(EnvVarError::err_on(name))
}
pub async fn with_setup(f: impl AsyncFnOnce() -> anyhow::Result<()>) {
println!("setting up logger and dotenv");
dotenv::dotenv().ok();