mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2025-06-11 19:03:21 +02:00
Move miette towards edges of BFFH for more structured error reporting
This commit is contained in:
@ -11,6 +11,8 @@ use rkyv::ser::serializers::AllocSerializer;
|
||||
use rkyv::ser::Serializer;
|
||||
use rkyv::Deserialize;
|
||||
|
||||
pub use crate::db::Error;
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
PartialEq,
|
||||
|
@ -11,6 +11,7 @@ use clap::ArgMatches;
|
||||
use miette::{Context, Diagnostic, IntoDiagnostic, SourceOffset, SourceSpan};
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
pub mod db;
|
||||
@ -69,17 +70,20 @@ pub struct Users {
|
||||
userdb: &'static UserDB,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Error, Diagnostic)]
|
||||
#[error(transparent)]
|
||||
#[repr(transparent)]
|
||||
pub struct Error(#[from] pub db::Error);
|
||||
|
||||
impl Users {
|
||||
pub fn new(env: Arc<Environment>) -> miette::Result<Self> {
|
||||
pub fn new(env: Arc<Environment>) -> Result<Self, Error> {
|
||||
let span = tracing::debug_span!("users", ?env, "Creating Users handle");
|
||||
let _guard = span.enter();
|
||||
|
||||
let userdb = USERDB
|
||||
.get_or_try_init(|| {
|
||||
tracing::debug!("Global resource not yet initialized, initializing…");
|
||||
unsafe { UserDB::create(env) }
|
||||
})
|
||||
.wrap_err("Failed to open userdb")?;
|
||||
let userdb = USERDB.get_or_try_init(|| {
|
||||
tracing::debug!("Global resource not yet initialized, initializing…");
|
||||
unsafe { UserDB::create(env) }
|
||||
})?;
|
||||
|
||||
Ok(Self { userdb })
|
||||
}
|
||||
|
Reference in New Issue
Block a user