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
58
59
60
61
62
63
64
65
66
//! Error kinds.

pub(crate) fn tag_mismatch(
    expected: crate::gimli::DwTag,
    actual: crate::gimli::DwTag,
) -> crate::Error {
    anyhow!(
        "tag mismatch; expected {:?}, received {:?}",
        expected.static_string(),
        actual.static_string()
    )
}

pub(crate) fn missing_attr(attr: crate::gimli::DwAt) -> crate::Error {
    anyhow!("DIE did not have attribute attr {:?}", attr.static_string())
}

pub(crate) fn invalid_attr(attr: crate::gimli::DwAt) -> crate::Error {
    anyhow!(
        "attribute {:?} had an unexpected form",
        attr.static_string()
    )
}

pub(crate) fn missing_child(tag: crate::gimli::DwTag) -> crate::Error {
    anyhow!(
        "DIE did not have expected child of tag {:?}",
        tag.static_string()
    )
}

pub(crate) fn size_mismatch(expected: usize, actual: usize) -> crate::Error {
    anyhow!("size mismatch; expected {expected} bytes, found {actual}.")
}

pub(crate) fn name_mismatch(expected: &'static str, actual: String) -> crate::Error {
    anyhow!("name mismatch; expected {expected} bytes, found {actual}.")
}

pub(crate) fn file_indexing() -> crate::Error {
    anyhow!("could not map file index to a file name")
}

pub(crate) fn arithmetic_overflow() -> crate::Error {
    anyhow!("arithmetic operation overflowed")
}

pub(crate) fn enum_destructure() -> crate::Error {
    anyhow!("could not destructure enum into variant")
}

/// Could not downcast the value into the given type.
#[derive(thiserror::Error, Debug)]
#[error("Could not downcast into {src}, received {dst}")]
pub struct DowncastErr {
    src: &'static str,
    dst: &'static str,
}

impl DowncastErr {
    pub(crate) fn new<Src, Dst>() -> Self {
        let src = std::any::type_name::<Src>();
        let dst = std::any::type_name::<Dst>();
        Self { src, dst }
    }
}