Skip to main content

driver_manager_utils/
errors.rs

1// Copyright 2026 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use fidl_fuchsia_component_sandbox as fsandbox;
6use thiserror::Error;
7
8#[derive(Debug, Error)]
9pub enum UtilsError {
10    #[error("FIDL error: {0}")]
11    Fidl(#[from] fidl::Error),
12    #[error("Unexpected capability type. Wanted: {0}, got: {1}")]
13    UnexpectedCapabilityType(String, String),
14    #[error("Unexpected routed type")]
15    UnexpectedRoutedType,
16    #[error("Sandbox error: {0}")]
17    SandboxError(String),
18    #[error("zx error: {0}")]
19    ZxStatus(zx::Status),
20}
21
22impl From<fsandbox::CapabilityStoreError> for UtilsError {
23    fn from(err: fsandbox::CapabilityStoreError) -> Self {
24        UtilsError::SandboxError(format!("CapabilityStoreError: {:?}", err))
25    }
26}
27
28impl From<fsandbox::RouterError> for UtilsError {
29    fn from(err: fsandbox::RouterError) -> Self {
30        UtilsError::SandboxError(format!("RouterError: {:?}", err))
31    }
32}
33
34impl From<i32> for UtilsError {
35    fn from(err: i32) -> Self {
36        UtilsError::ZxStatus(zx::Status::from_raw(err))
37    }
38}