Skip to main content

molframe_core/io/
structure_batch_diagnostics.rs

1//! Stable diagnostic codes for the bounded batch readers' error.
2
3use super::StructureBatchError;
4use crate::diagnostic::{Code, Diagnostic};
5
6impl From<&StructureBatchError> for Diagnostic {
7    /// A wrapped diagnostic is returned as it is, so its code, remedy and span
8    /// survive; the rest name the kind of limit that stopped the read.
9    fn from(error: &StructureBatchError) -> Self {
10        let code = match error {
11            StructureBatchError::Diagnostic(inner) => return inner.clone(),
12            StructureBatchError::DemandTooSmall { .. } => Code::E5101,
13            StructureBatchError::RecordExceedsBudget { .. } | StructureBatchError::Memory(_) => {
14                Code::E7001
15            }
16            StructureBatchError::Identity(_) | StructureBatchError::DictionaryFull => Code::E1903,
17        };
18        Self::new(code).with_message(error.to_string())
19    }
20}
21
22impl From<StructureBatchError> for Diagnostic {
23    fn from(error: StructureBatchError) -> Self {
24        Self::from(&error)
25    }
26}
27
28#[cfg(test)]
29#[path = "structure_batch_diagnostics_tests.rs"]
30mod tests;