1use crate::{
2 parser::types::FieldUnsupportedError,
3 types::{EventId, StreamId},
4};
5use std::io;
6use thiserror::Error;
7
8#[derive(Debug, Error)]
9pub enum Error {
10 #[error("Attempted to parse an invalid float size ({0})")]
11 InvalidFloatSize(usize),
12
13 #[error("Unsupported field type '{0}' (size {1}, alignment {2})")]
14 UnsupportedFieldType(String, usize, usize),
15
16 #[error("Unsupported alignment '{0}'")]
17 UnsupportedAlignment(String),
18
19 #[error("Encountered a CTF stream ID ({0}) that's not defined in the schema")]
20 UndefinedStreamId(StreamId),
21
22 #[error("Encountered a CTF event ID ({0}) that's not defined in the schema")]
23 UndefinedEventId(EventId),
24
25 #[error(
26 "Encountered and IO error while reading the input stream ({})",
27 .0.kind()
28 )]
29 Io(#[from] io::Error),
30}
31
32impl Error {
33 pub(crate) fn unsupported_ft<S: AsRef<str>>(f: S, ft: FieldUnsupportedError) -> Self {
34 Error::UnsupportedFieldType(f.as_ref().to_owned(), ft.0, ft.1)
35 }
36
37 pub(crate) fn unsupported_alignment<S: AsRef<str>>(f: S) -> Self {
38 Error::UnsupportedAlignment(f.as_ref().to_owned())
39 }
40}