Skip to main content

wrapper_events/
error.rs

1use serde_json::Value;
2use thiserror::Error;
3
4#[derive(Debug, Clone, Copy, Eq, PartialEq)]
5pub enum AdapterErrorCode {
6    JsonParse,
7    Normalize,
8    TypedParse,
9    Unknown,
10}
11
12#[derive(Debug, Clone, PartialEq)]
13pub struct CapturedRaw {
14    pub line: Option<String>,
15    pub json: Option<Value>,
16}
17
18#[derive(Debug, Error, Clone)]
19pub enum LineRecordError {
20    #[error("I/O error while reading wrapper output")]
21    Io,
22    #[error("invalid UTF-8 in wrapper output")]
23    InvalidUtf8,
24    #[error("line too long (observed_bytes={observed_bytes}, max_line_bytes={max_line_bytes})")]
25    LineTooLong {
26        observed_bytes: usize,
27        max_line_bytes: usize,
28    },
29    #[error("adapter parse failure ({code:?}): {summary}")]
30    Adapter {
31        code: AdapterErrorCode,
32        summary: String,
33    },
34}
35
36#[derive(Debug, Clone)]
37pub struct LineRecord<T> {
38    pub line_number: usize,
39    pub captured_raw: Option<CapturedRaw>,
40    pub outcome: Result<T, LineRecordError>,
41}
42
43#[derive(Debug, Clone)]
44pub struct ErrorDetail {
45    pub line_number: usize,
46    pub code: AdapterErrorCode,
47    pub adapter: &'static str,
48    pub details: String,
49}
50
51pub trait ErrorDetailSink: Send + 'static {
52    fn on_error(&mut self, detail: ErrorDetail);
53}