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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use crate::writer::Error as WriterError;
use diagnostics_hierarchy::Error as HierarchyError;
use inspect_format::{BlockIndex, BlockType, Error as FormatError};
use thiserror::Error;

#[derive(Debug, Error)]
pub enum ReaderError {
    #[error("FIDL error")]
    Fidl(#[source] anyhow::Error),

    #[error("Lazy node callback failed")]
    LazyCallback(#[source] anyhow::Error),

    #[error("expected header block on index 0")]
    MissingHeader,

    #[error("Cannot find parent block index {0}")]
    ParentIndexNotFound(BlockIndex),

    #[error("Malformed tree, no complete node with parent=0")]
    MalformedTree,

    #[error("VMO format error")]
    VmoFormat(#[source] FormatError),

    #[error("Tried to read more slots than available at block index {0}")]
    AttemptedToReadTooManyArraySlots(BlockIndex),

    #[error("unexpected array entry type format: {0:?}")]
    UnexpectedArrayEntryFormat(BlockType),

    #[error("Failed to parse name at index {0}")]
    ParseName(BlockIndex),

    #[error("Failed to get link content at index {0}")]
    GetLinkContent(BlockIndex),

    #[error("Failed to get extent at index {0}")]
    GetExtent(BlockIndex),

    #[error("Failed to get consistent snapshot")]
    InconsistentSnapshot,

    #[error("Header missing or is locked")]
    MissingHeaderOrLocked,

    #[error("Cannot read from no-op Inspector")]
    NoOpInspector,

    #[cfg(target_os = "fuchsia")]
    #[error("Failed to call vmo")]
    Vmo(fuchsia_zircon::Status),

    #[error("Error creating node hierarchy")]
    Hierarchy(#[source] HierarchyError),

    #[error("Failed to duplicate vmo handle")]
    DuplicateVmo,

    #[error("Failed to fetch vmo from Tree content")]
    FetchVmo,

    #[error("Failed to load tree name {0}")]
    FailedToLoadTree(String),

    #[error("Timed out reading tree")]
    TreeTimedOut,

    #[error("Failed to lock inspector state")]
    FailedToLockState(#[source] WriterError),

    #[error("Offset out of bounds while reading")]
    OffsetOutOfBounds,
}

impl From<FormatError> for ReaderError {
    fn from(error: FormatError) -> Self {
        Self::VmoFormat(error)
    }
}