➖ Remove ResultExt and adapt function results
This commit is contained in:
parent
ce3e0257bf
commit
3dac2c4a73
8 changed files with 35 additions and 20 deletions
|
|
@ -48,7 +48,6 @@ url = "2.4.0"
|
||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
tracing-appender = "0.2.2"
|
tracing-appender = "0.2.2"
|
||||||
tracing-subscriber = { version = "0.3.17", features = ["json", "env-filter"] }
|
tracing-subscriber = { version = "0.3.17", features = ["json", "env-filter"] }
|
||||||
tracing-unwrap = { version = "0.10.0", default-features = false }
|
|
||||||
tracing-actix-web = "0.7.6"
|
tracing-actix-web = "0.7.6"
|
||||||
|
|
||||||
fluent-templates = "0.8.0"
|
fluent-templates = "0.8.0"
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::core::action::add_action;
|
use crate::core::action::add_action;
|
||||||
use crate::core::module::ModuleRef;
|
use crate::core::module::ModuleRef;
|
||||||
use crate::core::theme::all::THEMES;
|
use crate::core::theme::all::THEMES;
|
||||||
use crate::locale::L10n;
|
use crate::{service, trace, LazyStatic};
|
||||||
use crate::{service, trace, LazyStatic, ResultExt};
|
|
||||||
|
|
||||||
#[cfg(feature = "database")]
|
#[cfg(feature = "database")]
|
||||||
use crate::db::*;
|
use crate::db::*;
|
||||||
|
|
@ -111,7 +110,9 @@ pub fn init_modules() {
|
||||||
#[cfg(feature = "database")]
|
#[cfg(feature = "database")]
|
||||||
pub fn run_migrations() {
|
pub fn run_migrations() {
|
||||||
if let Some(dbconn) = &*DBCONN {
|
if let Some(dbconn) = &*DBCONN {
|
||||||
run_now({
|
use crate::locale::L10n;
|
||||||
|
|
||||||
|
match run_now({
|
||||||
struct Migrator;
|
struct Migrator;
|
||||||
impl MigratorTrait for Migrator {
|
impl MigratorTrait for Migrator {
|
||||||
fn migrations() -> Vec<MigrationItem> {
|
fn migrations() -> Vec<MigrationItem> {
|
||||||
|
|
@ -123,10 +124,16 @@ pub fn run_migrations() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Migrator::up(SchemaManagerConnection::Connection(dbconn), None)
|
Migrator::up(SchemaManagerConnection::Connection(dbconn), None)
|
||||||
})
|
}) {
|
||||||
.expect_or_log(L10n::l("db_migration_fail").error().as_str());
|
Err(e) => {
|
||||||
|
L10n::l("db_migration_fail")
|
||||||
|
.with_arg("dberr", format!("{}", e))
|
||||||
|
.error();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
|
||||||
run_now({
|
match run_now({
|
||||||
struct Migrator;
|
struct Migrator;
|
||||||
impl MigratorTrait for Migrator {
|
impl MigratorTrait for Migrator {
|
||||||
fn migrations() -> Vec<MigrationItem> {
|
fn migrations() -> Vec<MigrationItem> {
|
||||||
|
|
@ -138,8 +145,14 @@ pub fn run_migrations() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Migrator::down(SchemaManagerConnection::Connection(dbconn), None)
|
Migrator::down(SchemaManagerConnection::Connection(dbconn), None)
|
||||||
})
|
}) {
|
||||||
.expect_or_log(L10n::l("db_migration_fail").error().as_str());
|
Err(e) => {
|
||||||
|
L10n::l("db_migration_fail")
|
||||||
|
.with_arg("dberr", format!("{}", e))
|
||||||
|
.error();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
//! Acceso unificado y normalizado a base de datos.
|
//! Acceso unificado y normalizado a base de datos.
|
||||||
|
|
||||||
use crate::locale::L10n;
|
use crate::locale::L10n;
|
||||||
use crate::{config, trace, LazyStatic, ResultExt};
|
use crate::{config, trace, LazyStatic};
|
||||||
|
|
||||||
pub use url::Url as DbUri;
|
pub use url::Url as DbUri;
|
||||||
|
|
||||||
|
|
@ -70,7 +70,7 @@ pub(crate) static DBCONN: LazyStatic<Option<DbConn>> = LazyStatic::new(|| {
|
||||||
db_opt.max_connections(config::SETTINGS.database.max_pool_size);
|
db_opt.max_connections(config::SETTINGS.database.max_pool_size);
|
||||||
db_opt
|
db_opt
|
||||||
}))
|
}))
|
||||||
.expect_or_log(L10n::l("db_connection_fail").to_string().as_str()),
|
.expect(L10n::l("db_connection_fail").to_string().as_str()),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
@ -93,7 +93,7 @@ pub async fn query<Q: QueryStatementWriter>(stmt: &mut Q) -> Result<Vec<QueryRes
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
None => Err(DbErr::Conn(RuntimeErr::Internal(
|
None => Err(DbErr::Conn(RuntimeErr::Internal(
|
||||||
L10n::l("db_connection_not_initialized").trace(),
|
L10n::l("db_connection_not_initialized").debug(),
|
||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -114,7 +114,7 @@ pub async fn exec<Q: QueryStatementWriter>(stmt: &mut Q) -> Result<Option<QueryR
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
None => Err(DbErr::Conn(RuntimeErr::Internal(
|
None => Err(DbErr::Conn(RuntimeErr::Internal(
|
||||||
L10n::l("db_connection_not_initialized").trace(),
|
L10n::l("db_connection_not_initialized").debug(),
|
||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -128,7 +128,7 @@ pub async fn exec_raw(stmt: String) -> Result<ExecResult, DbErr> {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
None => Err(DbErr::Conn(RuntimeErr::Internal(
|
None => Err(DbErr::Conn(RuntimeErr::Internal(
|
||||||
L10n::l("db_connection_not_initialized").trace(),
|
L10n::l("db_connection_not_initialized").debug(),
|
||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,6 @@ pub use pagetop_macros::{fn_builder, main, test};
|
||||||
|
|
||||||
pub use once_cell::sync::Lazy as LazyStatic;
|
pub use once_cell::sync::Lazy as LazyStatic;
|
||||||
pub use static_files::Resource as StaticResource;
|
pub use static_files::Resource as StaticResource;
|
||||||
pub use tracing_unwrap::ResultExt;
|
|
||||||
|
|
||||||
pub type Handle = u64;
|
pub type Handle = u64;
|
||||||
pub type Weight = i8;
|
pub type Weight = i8;
|
||||||
|
|
|
||||||
|
|
@ -114,11 +114,15 @@ static LANGUAGES: LazyStatic<HashMap<String, (LanguageIdentifier, &str)>> = Lazy
|
||||||
|
|
||||||
static FALLBACK_LANGID: LazyStatic<LanguageIdentifier> = LazyStatic::new(|| langid!("en-US"));
|
static FALLBACK_LANGID: LazyStatic<LanguageIdentifier> = LazyStatic::new(|| langid!("en-US"));
|
||||||
|
|
||||||
|
pub fn langid_fallback() -> &'static LanguageIdentifier {
|
||||||
|
&FALLBACK_LANGID
|
||||||
|
}
|
||||||
|
|
||||||
/// Almacena el Identificador de Idioma Unicode
|
/// Almacena el Identificador de Idioma Unicode
|
||||||
/// ([Unicode Language Identifier](https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier))
|
/// ([Unicode Language Identifier](https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier))
|
||||||
/// global para la aplicación a partir de `SETTINGS.app.language`.
|
/// global para la aplicación a partir de `SETTINGS.app.language`.
|
||||||
pub(crate) static LANGID: LazyStatic<&LanguageIdentifier> = LazyStatic::new(|| {
|
pub(crate) static LANGID: LazyStatic<&LanguageIdentifier> = LazyStatic::new(|| {
|
||||||
langid_for(config::SETTINGS.app.language.as_str()).unwrap_or(&FALLBACK_LANGID)
|
langid_for(config::SETTINGS.app.language.as_str()).unwrap_or(langid_fallback())
|
||||||
});
|
});
|
||||||
|
|
||||||
pub fn langid_for(language: impl Into<String>) -> Result<&'static LanguageIdentifier, String> {
|
pub fn langid_for(language: impl Into<String>) -> Result<&'static LanguageIdentifier, String> {
|
||||||
|
|
@ -131,7 +135,7 @@ pub fn langid_for(language: impl Into<String>) -> Result<&'static LanguageIdenti
|
||||||
} else {
|
} else {
|
||||||
Err(L10n::l(LANGUAGE_SET_FAILURE)
|
Err(L10n::l(LANGUAGE_SET_FAILURE)
|
||||||
.with_arg("language", config::SETTINGS.app.language.as_str())
|
.with_arg("language", config::SETTINGS.app.language.as_str())
|
||||||
.warn())
|
.debug())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,4 @@ language_set_failure = Failed to set language. Unicode Language Identifier "{$la
|
||||||
|
|
||||||
db_connection_fail = Failed to connect to database
|
db_connection_fail = Failed to connect to database
|
||||||
db_connection_not_initialized = Database connection not initialized
|
db_connection_not_initialized = Database connection not initialized
|
||||||
db_migration_fail = Database update failed
|
db_migration_fail = Database update failed (${dberr})
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,4 @@ language_set_failure = Fallo al asignar idioma. El Identificador de Lenguaje Uni
|
||||||
|
|
||||||
db_connection_fail = Fallo al conectar con la base de datos
|
db_connection_fail = Fallo al conectar con la base de datos
|
||||||
db_connection_not_initialized = Conexión a la base de datos no inicializada
|
db_connection_not_initialized = Conexión a la base de datos no inicializada
|
||||||
db_migration_fail = Fallo en la actualización de la base de datos
|
db_migration_fail = Fallo al actualizar base de datos (${dberr})
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
pub use crate::{concat_string, fn_builder, main, paste, test};
|
pub use crate::{concat_string, fn_builder, main, paste, test};
|
||||||
|
|
||||||
// Global.
|
// Global.
|
||||||
pub use crate::{Handle, HashMapResources, LazyStatic, ResultExt, Weight};
|
pub use crate::{Handle, HashMapResources, LazyStatic, Weight};
|
||||||
|
|
||||||
// Functions and macro helpers.
|
// Functions and macro helpers.
|
||||||
pub use crate::util;
|
pub use crate::util;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue