1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::{io, str::Utf8Error};

use thiserror::Error;

#[derive(Error, Debug)]
pub enum BuildAttrError {
    #[error("no data")]
    NoData,
    #[error("incompatible format version")]
    IncompatibleVersion(u8),
}

#[derive(Error, Debug)]
pub enum ReadError {
    #[error("IO error")]
    Io(io::Error),
    #[error("UTF8 error")]
    Utf8(Utf8Error),
    #[error("no more data (EOF reached)")]
    Eof,
    #[error("index out of bounds")]
    OutOfBounds,
}

#[derive(Error, Debug)]
pub enum PublicAttrsError {
    #[error("invalid subsection name, should be 'aeabi'")]
    InvalidName(String),
    #[error("tag error")]
    Tag(TagError),
    #[error("no tags")]
    NoTags,
    #[error("expected first tag to be a file tag")]
    NoFileTag,
    #[error("duplicate file tag")]
    DuplicateFileTag,
    #[error("expected to be in file scope")]
    NotFileScope,
    #[error("expected to be in section scope")]
    NotSectionScope,
    #[error("enclosed scope ends before parent scope")]
    ScopeEndsBeforeParent,
}

#[derive(Error, Debug)]
pub enum TagError {
    #[error("incompatible tag value")]
    IncompatibleTagValue(u8),
    #[error("read error")]
    Read(ReadError),
    #[error("invalid scope tag")]
    InvalidScopeTag,
    #[error("expected null")]
    ExpectedNull,
    #[error("nested scope tag")]
    NestedScopeTag,
}