chore: update i18n

This commit is contained in:
wonfen
2026-07-24 11:53:50 +08:00
parent 82c486923b
commit bce83d5c6f
123 changed files with 2178 additions and 277 deletions
+29
View File
@@ -3,6 +3,12 @@ use smartstring::alias::String;
pub type CmdResult<T = ()> = Result<T, String>;
const USER_ERROR_PREFIX: &str = "CVR_ERROR:";
pub fn coded_error(code: &str, detail: impl std::fmt::Display) -> String {
format!("{USER_ERROR_PREFIX}{code}\n{detail}").into()
}
// Command modules
pub mod app;
pub mod backup;
@@ -46,6 +52,10 @@ pub trait StringifyErr<T> {
F: Fn(&str);
}
pub trait WithErrorCode<T> {
fn with_error_code(self, code: &str) -> CmdResult<T>;
}
impl<T, E: std::fmt::Display> StringifyErr<T> for Result<T, E> {
fn stringify_err(self) -> CmdResult<T> {
self.map_err(|e| e.to_string().into())
@@ -62,3 +72,22 @@ impl<T, E: std::fmt::Display> StringifyErr<T> for Result<T, E> {
})
}
}
impl<T, E: std::fmt::Display> WithErrorCode<T> for Result<T, E> {
fn with_error_code(self, code: &str) -> CmdResult<T> {
self.map_err(|error| coded_error(code, error))
}
}
#[cfg(test)]
mod tests {
use super::coded_error;
#[test]
fn coded_error_preserves_stable_code_and_diagnostic_detail() {
assert_eq!(
coded_error("CORE_RESTART_FAILED", "connection refused"),
"CVR_ERROR:CORE_RESTART_FAILED\nconnection refused"
);
}
}