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
// 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::Ref, fidl_fuchsia_component_test as ftest, thiserror::Error};

#[derive(Debug, Error)]
pub enum Error {
    #[error("route is missing source")]
    MissingSource,

    #[error("the realm builder server returned an error: {0:?}")]
    ServerError(ftest::RealmBuilderError),

    #[error("an internal error was encountered while working with the realm builder server")]
    FidlError(#[from] fidl::Error),

    #[error("failed to open \"/pkg\": {0:?}")]
    FailedToOpenPkgDir(fuchsia_fs::node::OpenError),

    #[error("failed to connect to realm builder server: {0:?}")]
    ConnectToServer(anyhow::Error),

    #[error("unable to destroy realm, the destroy waiter for root has already been taken")]
    DestroyWaiterTaken,

    #[error("failed to bind to realm: {0:?}")]
    FailedToBind(anyhow::Error),

    #[error("failed to create child: {0:?}")]
    FailedToCreateChild(anyhow::Error),

    #[error("failed to destroy child: {0:?}")]
    FailedToDestroyChild(anyhow::Error),

    #[error("unable to use reference {0} in realm {1:?}")]
    RefUsedInWrongRealm(Ref, String),

    #[error("could not start root component using lifecycle controller: {0:?}")]
    CannotStartRootComponent(anyhow::Error),
}

impl From<ftest::RealmBuilderError> for Error {
    fn from(err: ftest::RealmBuilderError) -> Self {
        Self::ServerError(err)
    }
}

// TODO: Define an error type for ScopedInstance