khive_vcs_adapters/error.rs
1// Copyright 2026 Haiyang Li. Licensed under Apache-2.0.
2//
3//! Adapter error type.
4
5use thiserror::Error;
6
7/// An error produced by a format adapter.
8///
9/// Fatal errors (missing required fields, structural failures) are non-recoverable:
10/// the adapter aborts and the caller must handle the error atomically. Non-fatal
11/// issues (unknown but non-required fields) are warnings reported in the import
12/// summary.
13#[derive(Debug, Error)]
14pub enum AdapterError {
15 /// A required field is missing from a record.
16 #[error("record {index}: missing required field '{field}'")]
17 MissingField { index: usize, field: String },
18
19 /// A field has an unexpected type or value.
20 #[error("record {index}: invalid value for field '{field}': {reason}")]
21 InvalidField {
22 index: usize,
23 field: String,
24 reason: String,
25 },
26
27 /// The source file cannot be parsed (structural failure).
28 #[error("parse error: {0}")]
29 Parse(String),
30
31 /// An entity kind is unknown under strict schema mode.
32 #[error("record {index}: unknown entity kind '{kind}'")]
33 UnknownKind { index: usize, kind: String },
34
35 /// An edge relation is not in the closed set of 15 canonical relations.
36 ///
37 /// This is always an error regardless of `--schema-mode`.
38 #[error("record {index}: unknown edge relation '{relation}'")]
39 UnknownRelation { index: usize, relation: String },
40
41 /// A deferred format was requested.
42 #[error("format '{format}' is not yet implemented (deferred to P1/P2)")]
43 NotYetImplemented { format: String },
44}