feat(typedef/error-type): implement TypedefError enum with Schema, Offset, Access, Validation variants

This commit is contained in:
glm-5.2 committed 2026-07-21 09:55:46 +00:00
1 parent 44f221e8cc
commit 109d743f9f
3 files changed
+50 -4

No files matched your search

+45 -1
View File
@@ -4,4 +4,48 @@
//! conditions across the engine's three phases (schema parsing, offset
//! computation, read/write) plus validation.
// TODO: implement
use std::fmt;
/// Errors produced by the typedef engine across all phases.
#[derive(Debug)]
pub enum TypedefError {
/// Schema parsing errors — invalid JSON, missing required keywords,
/// unknown `TypeDef:*` kinds, malformed annotations.
Schema(String),
/// Offset computation errors — field not found, type not supported
/// for offset computation, recursive depth exceeded.
Offset {
field_path: String,
reason: String,
},
/// Read/write errors — buffer too short, invalid UTF-8, value out
/// of range for the target type.
Access {
field_path: String,
reason: String,
},
/// Validation errors — delegated to the `jsonschema` crate.
/// The `'static` lifetime is correct: the validator owns its schema
/// reference and lives for the lifetime of the `TypedefEngine`.
Validation(jsonschema::ValidationError<'static>),
}
impl fmt::Display for TypedefError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TypedefError::Schema(msg) => write!(f, "schema error: {msg}"),
TypedefError::Offset { field_path, reason } => {
write!(f, "offset error at {field_path}: {reason}")
}
TypedefError::Access { field_path, reason } => {
write!(f, "access error at {field_path}: {reason}")
}
TypedefError::Validation(inner) => write!(f, "validation error: {inner}"),
}
}
}
impl std::error::Error for TypedefError {}
+3 -1
View File
@@ -29,4 +29,6 @@ pub mod offset_map;
pub mod schema;
pub mod sequential_reader;
pub mod tunion;
pub mod validation;
pub mod validation;
pub use error::TypedefError;
+2 -2
View File
@@ -1,7 +1,7 @@
---
id: typedef/error-type
name: Implement TypedefError enum with Schema, Offset, Access, and Validation variants
status: pending
status: completed
depends_on: [typedef/crate-init]
scope: narrow
risk: low
@@ -107,4 +107,4 @@ Since the `jsonschema` crate is a dependency, this is straightforward.
## Summary
> To be filled on completion
Implemented the `TypedefError` enum in `crates/alknet-typedef/src/error.rs` with four variants (`Schema`, `Offset`, `Access`, `Validation`) per ADR-098, plus `Display` (with field-path-aware messages for `Offset` and `Access`) and `std::error::Error` impls and a derived `Debug`. Re-exported `TypedefError` from `crates/alknet-typedef/src/lib.rs` so it is accessible as `alknet_typedef::TypedefError`. `cargo check`, `cargo clippy -D warnings`, and `cargo build --workspace` all pass with no warnings.