Use thiserror instead of derive_more (#44)

- Use thiserror instead of derive_more
- Format code
- Fix clippy warnings
- Add LICENSE_TEMPLATE

Signed-off-by: koushiro <koushiro.cqx@gmail.com>
This commit is contained in:
Qinxuan Chen
2019-11-26 20:09:17 +08:00
committed by Andrew Jones
parent 40a8ed3f58
commit 4769b4b016
14 changed files with 414 additions and 205 deletions
+44 -15
View File
@@ -14,41 +14,70 @@
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
use jsonrpc_core_client::RpcError;
use runtime_primitives::transaction_validity::TransactionValidityError;
use substrate_primitives::crypto::SecretStringError;
use crate::{
events::EventsError,
metadata::MetadataError,
};
use jsonrpc_core_client::RpcError;
use parity_scale_codec::Error as CodecError;
use runtime_primitives::transaction_validity::TransactionValidityError;
use std::io::Error as IoError;
use substrate_primitives::crypto::SecretStringError;
/// Error enum.
#[derive(Debug, derive_more::From, derive_more::Display)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// Codec error.
Codec(CodecError),
/// Events error.
Events(EventsError),
/// Io error.
Io(IoError),
#[error("Io error: {0}")]
Io(#[from] std::io::Error),
/// Codec error.
#[error("Scale codec error: {0}")]
Codec(#[from] parity_scale_codec::Error),
/// Rpc error.
#[error("Rpc error: {0}")]
Rpc(RpcError),
/// Secret string error.
#[display(fmt = "Secret String Error")]
#[error("Secret String Error")]
SecretString(SecretStringError),
/// Metadata error.
Metadata(MetadataError),
/// Extrinsic validity error
#[display(fmt = "Transaction Validity Error: {:?}", _0)]
#[error("Transaction Validity Error: {0:?}")]
Invalid(TransactionValidityError),
/// Events error.
#[error("Event error: {0}")]
Events(#[from] EventsError),
/// Metadata error.
#[error("Metadata error: {0}")]
Metadata(#[from] MetadataError),
/// Other error.
#[error("Other error: {0}")]
Other(String),
}
impl From<RpcError> for Error {
fn from(error: RpcError) -> Self {
Error::Rpc(error)
}
}
impl From<SecretStringError> for Error {
fn from(error: SecretStringError) -> Self {
Error::SecretString(error)
}
}
impl From<TransactionValidityError> for Error {
fn from(error: TransactionValidityError) -> Self {
Error::Invalid(error)
}
}
impl From<&str> for Error {
fn from(error: &str) -> Self {
Error::Other(error.into())
}
}
impl From<String> for Error {
fn from(error: String) -> Self {
Error::Other(error)
}
}