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:
@@ -197,16 +197,26 @@ pub(crate) struct RawCell {
|
||||
pub was_quoted: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum CsvError {
|
||||
#[error("CSV is empty")]
|
||||
Empty,
|
||||
#[error("invalid UTF-8 in CSV body")]
|
||||
InvalidUtf8,
|
||||
#[error("unterminated quoted field")]
|
||||
UnterminatedQuote,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for CsvError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let key = match self {
|
||||
Self::Empty => "persistence.csv.empty",
|
||||
Self::InvalidUtf8 => "persistence.csv.invalid_utf8",
|
||||
Self::UnterminatedQuote => "persistence.csv.unterminated_quote",
|
||||
};
|
||||
f.write_str(&crate::friendly::translate(key, &[]))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for CsvError {}
|
||||
|
||||
/// Tokenize a CSV body. Returns the header (column names from
|
||||
/// the first record) and the data rows. Each cell preserves a
|
||||
/// `was_quoted` flag so the caller can distinguish an empty
|
||||
|
||||
Reference in New Issue
Block a user