github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/adm/src/err.rs (about) 1 /* 2 * Copyright 2018 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * ------------------------------------------------------------------------------ 16 */ 17 18 use std; 19 20 #[derive(Debug)] 21 pub enum CliError { 22 ArgumentError(String), 23 EnvironmentError(String), 24 ParseError(String), 25 } 26 27 impl std::fmt::Display for CliError { 28 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 29 match *self { 30 CliError::ArgumentError(ref msg) => write!(f, "ArgumentError: {}", msg), 31 CliError::EnvironmentError(ref msg) => write!(f, "EnvironmentError: {}", msg), 32 CliError::ParseError(ref msg) => write!(f, "ParseError: {}", msg), 33 } 34 } 35 } 36 37 impl std::error::Error for CliError { 38 fn description(&self) -> &str { 39 match *self { 40 CliError::ArgumentError(ref msg) => msg, 41 CliError::EnvironmentError(ref msg) => msg, 42 CliError::ParseError(ref msg) => msg, 43 } 44 } 45 46 fn cause(&self) -> Option<&std::error::Error> { 47 match *self { 48 CliError::ArgumentError(_) => None, 49 CliError::EnvironmentError(_) => None, 50 CliError::ParseError(_) => None, 51 } 52 } 53 }