error.rs 1.85 KB
Newer Older
1
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
2
// This file is part of ink!.
3
//
4
// ink! is free software: you can redistribute it and/or modify
5 6 7 8
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
9
// ink! is distributed in the hope that it will be useful,
10 11 12 13 14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
15
// along with ink!.  If not, see <http://www.gnu.org/licenses/>.
16

Andrew Jones's avatar
Andrew Jones committed
17
use jsonrpc_core_client::RpcError;
18 19
use std::{
    io::Error as IoError,
Robin Freyler's avatar
Robin Freyler committed
20
    result::Result as StdResult,
21
};
Andrew Jones's avatar
Andrew Jones committed
22 23
use substrate_primitives::crypto::SecretStringError;
use subxt::Error as SubXtError;
24
use zip::result::ZipError;
25

26 27 28
/// An error that can be encountered while executing commands.
#[derive(Debug, derive_more::From, derive_more::Display)]
pub enum CommandError {
29
    Io(IoError),
30
    #[display(fmt = "Command unimplemented")]
31
    UnimplementedCommand,
32
    #[display(fmt = "Abstraction layer unimplemented")]
33
    UnimplementedAbstractionLayer,
Andrew Jones's avatar
Andrew Jones committed
34 35 36 37
    Rpc(RpcError),
    #[display(fmt = "Secret string error")]
    SecretString(SecretStringError),
    SubXt(SubXtError),
38
    ZipError(ZipError),
39 40 41 42 43 44
    BuildFailed,
    #[display(fmt = "Error invoking `cargo metadata`")]
    CargoMetadata(cargo_metadata::Error),
    WasmDeserialization(parity_wasm::elements::Error),
    #[display(fmt = "Optimizer failed")]
    Optimizer(pwasm_utils::OptimizerError),
45
    Other(String),
46 47
}

48 49
impl From<&str> for CommandError {
    fn from(error: &str) -> Self {
50
        CommandError::Other(error.into())
51 52 53 54 55
    }
}

/// Result type that has a `CommandError`.
pub type Result<T> = StdResult<T, CommandError>;