github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/adm/src/database/error.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 DatabaseError {
    22      InitError(String),
    23      ReaderError(String),
    24      WriterError(String),
    25      CorruptionError(String),
    26      NotFoundError(String),
    27  }
    28  
    29  impl std::fmt::Display for DatabaseError {
    30      fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
    31          match *self {
    32              DatabaseError::InitError(ref msg) => write!(f, "InitError: {}", msg),
    33              DatabaseError::ReaderError(ref msg) => write!(f, "ReaderError: {}", msg),
    34              DatabaseError::WriterError(ref msg) => write!(f, "WriterError: {}", msg),
    35              DatabaseError::CorruptionError(ref msg) => write!(f, "CorruptionError: {}", msg),
    36              DatabaseError::NotFoundError(ref msg) => write!(f, "NotFoundError: {}", msg),
    37          }
    38      }
    39  }
    40  
    41  impl std::error::Error for DatabaseError {
    42      fn description(&self) -> &str {
    43          match *self {
    44              DatabaseError::InitError(ref msg) => msg,
    45              DatabaseError::ReaderError(ref msg) => msg,
    46              DatabaseError::WriterError(ref msg) => msg,
    47              DatabaseError::CorruptionError(ref msg) => msg,
    48              DatabaseError::NotFoundError(ref msg) => msg,
    49          }
    50      }
    51  
    52      fn cause(&self) -> Option<&std::error::Error> {
    53          match *self {
    54              DatabaseError::InitError(_) => None,
    55              DatabaseError::ReaderError(_) => None,
    56              DatabaseError::WriterError(_) => None,
    57              DatabaseError::CorruptionError(_) => None,
    58              DatabaseError::NotFoundError(_) => None,
    59          }
    60      }
    61  }