1use crate::logs::error::LogsError;
6use fidl::prelude::*;
7use fidl_fuchsia_diagnostics::BatchIteratorControlHandle;
8use log::warn;
9use thiserror::Error;
10use zx_status::Status as ZxStatus;
11
12#[derive(Debug, Error)]
13pub enum Error {
14 #[error(transparent)]
15 Logs(#[from] LogsError),
16
17 #[error("Failed to serve outgoing dir: {0}")]
18 ServeOutgoing(#[source] anyhow::Error),
19
20 #[error(transparent)]
21 Inspect(#[from] fuchsia_inspect::Error),
22
23 #[error("Encountered a diagnostics data repository node with more than one artifact container. {0:?}")]
24 MultipleArtifactContainers(Vec<String>),
25
26 #[error(transparent)]
27 Hierarchy(#[from] diagnostics_hierarchy::Error),
28
29 #[error(transparent)]
30 Selectors(#[from] anyhow::Error),
31}
32
33#[derive(Debug, Error)]
34pub enum AccessorError {
35 #[error("data_type must be set")]
36 MissingDataType,
37
38 #[error("client_selector_configuration must be set")]
39 MissingSelectors,
40
41 #[error("no selectors were provided")]
42 EmptySelectors,
43
44 #[error("requested selectors are unsupported: {}", .0)]
45 InvalidSelectors(&'static str),
46
47 #[error("couldn't parse/validate the provided selectors: {}", .0)]
48 ParseSelectors(#[from] selectors::Error),
49
50 #[error("only selectors of type `component:root` are supported for logs at the moment")]
51 InvalidLogSelector,
52
53 #[error("format must be set")]
54 MissingFormat,
55
56 #[error("only JSON supported right now")]
57 UnsupportedFormat,
58
59 #[error("stream_mode must be set")]
60 MissingMode,
61
62 #[error("only snapshot supported right now")]
63 UnsupportedMode,
64
65 #[error("IPC failure")]
66 Ipc {
67 #[from]
68 source: fidl::Error,
69 },
70
71 #[error("Unable to create a VMO -- extremely unusual!")]
72 VmoCreate(#[source] ZxStatus),
73
74 #[error("Unable to write to VMO -- we may be OOMing")]
75 VmoWrite(#[source] ZxStatus),
76
77 #[error("Unable to get VMO size -- extremely unusual")]
78 VmoSize(#[source] ZxStatus),
79
80 #[error("JSON serialization failure: {0}")]
81 Serialization(#[from] serde_json::Error),
82
83 #[error("CBOR serialization failure: {0}")]
84 CborSerialization(#[source] anyhow::Error),
85
86 #[error("batch timeout was set on StreamParameter and on PerformanceConfiguration")]
87 DuplicateBatchTimeout,
88
89 #[error("IO error: {0}")]
90 Io(#[from] std::io::Error),
91}
92
93impl AccessorError {
94 pub fn close(self, control: BatchIteratorControlHandle) {
95 warn!(error:% = self; "Closing BatchIterator.");
96 let epitaph = match self {
97 AccessorError::DuplicateBatchTimeout
98 | AccessorError::MissingDataType
99 | AccessorError::EmptySelectors
100 | AccessorError::MissingSelectors
101 | AccessorError::InvalidSelectors(_)
102 | AccessorError::InvalidLogSelector
103 | AccessorError::ParseSelectors(_) => ZxStatus::INVALID_ARGS,
104 AccessorError::VmoCreate(status)
105 | AccessorError::VmoWrite(status)
106 | AccessorError::VmoSize(status) => status,
107 AccessorError::MissingFormat | AccessorError::MissingMode => ZxStatus::INVALID_ARGS,
108 AccessorError::UnsupportedFormat | AccessorError::UnsupportedMode => {
109 ZxStatus::WRONG_TYPE
110 }
111 AccessorError::Serialization { .. } => ZxStatus::BAD_STATE,
112 AccessorError::CborSerialization { .. } => ZxStatus::BAD_STATE,
113 AccessorError::Ipc { .. } | AccessorError::Io(_) => ZxStatus::IO,
114 };
115 control.shutdown_with_epitaph(epitaph);
116 }
117}