round-5 follow-up r2: migrate all thiserror Display attributes to catalog
Completes the i18n sweep started in the previous commit. All
remaining hand-rolled user-facing English strings inside
thiserror #[error(...)] attributes have been moved into the
catalog. Drops the thiserror dependency entirely.
Twelve error types migrated:
- dsl::action::UnknownAction → parse.custom.unknown_action
- dsl::parser::ParseError → parse.error_wrapper + parse.empty
- dsl::value::ValueError → value.{type_mismatch,format}
- persistence::csv_io::CsvError → persistence.csv.*
- persistence::mod::PersistenceError → persistence.{io,encode}
- persistence::yaml::YamlError → persistence.yaml.*
- persistence::migrations::MigrateError → persistence.migrate.*
- project::lock::LockError → project.lock.*
- project::naming::NamingError → project.naming.*
- project::naming::UserNameError → project.user_name.*
- project::mod::ProjectError → project.{path_not_found,...}
- project::mod::SafeDeleteError → project.safe_delete.*
- archive::ArchiveError → archive.*
- cli::ArgsError → cli.*
- db::DbError → db.error.*
Pattern per type: drop thiserror::Error derive, write manual
Display calling crate::t!(), keep #[from] semantics via
explicit From impls, override Error::source() where applicable
so #[source]-style chaining is preserved.
Why this matters (user rationale): "fine to have fallbacks for
errors that are purely technical, but lift the output to a
place where it can be localized later and where an adjustment
with friendly text is easily possible if any of them become
part of the happy path." All surface strings now live in
en-US.yaml and can be reworded or localized without touching
Rust source.
Tests: 769 passing, 0 failed, 1 ignored. Clippy clean with
-D warnings. Cargo.toml: drop thiserror = "2.0.18".
This commit is contained in:
+37
-8
@@ -33,30 +33,59 @@ pub struct Lock {
|
||||
path: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[derive(Debug)]
|
||||
pub enum LockError {
|
||||
#[error(
|
||||
"project is already open in another rdbms-playground process \
|
||||
(pid {pid} on host `{hostname}`); close that process or \
|
||||
remove `{path}` if you're sure it's not running"
|
||||
)]
|
||||
AlreadyHeld {
|
||||
pid: u32,
|
||||
hostname: String,
|
||||
path: PathBuf,
|
||||
},
|
||||
#[error("could not write lock file `{path}`: {source}")]
|
||||
Write {
|
||||
path: PathBuf,
|
||||
source: std::io::Error,
|
||||
},
|
||||
#[error("could not read existing lock file `{path}`: {source}")]
|
||||
Read {
|
||||
path: PathBuf,
|
||||
source: std::io::Error,
|
||||
},
|
||||
}
|
||||
|
||||
impl std::fmt::Display for LockError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::AlreadyHeld {
|
||||
pid,
|
||||
hostname,
|
||||
path,
|
||||
} => f.write_str(&crate::t!(
|
||||
"project.lock.already_held",
|
||||
pid = pid,
|
||||
hostname = hostname,
|
||||
path = path.display(),
|
||||
)),
|
||||
Self::Write { path, source } => f.write_str(&crate::t!(
|
||||
"project.lock.write",
|
||||
path = path.display(),
|
||||
source = source,
|
||||
)),
|
||||
Self::Read { path, source } => f.write_str(&crate::t!(
|
||||
"project.lock.read",
|
||||
path = path.display(),
|
||||
source = source,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for LockError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::AlreadyHeld { .. } => None,
|
||||
Self::Write { source, .. } | Self::Read { source, .. } => Some(source),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Lock {
|
||||
/// Attempt to acquire the lock for `project_dir`. The
|
||||
/// directory itself must exist; `Project::open` /
|
||||
|
||||
Reference in New Issue
Block a user