-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy patherrors.rs
More file actions
78 lines (68 loc) · 1.79 KB
/
errors.rs
File metadata and controls
78 lines (68 loc) · 1.79 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2019-2026 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT
use std::{borrow::Cow, fmt::Debug};
use crate::blocks::CreateTipsetError;
use cid::Error as CidErr;
use fil_actors_shared::fvm_ipld_amt::Error as AmtErr;
use fvm_ipld_encoding::Error as EncErr;
use thiserror::Error;
/// Chain error
#[derive(Debug, Error)]
pub enum Error {
/// Key was not found
#[error("Invalid tipset: {0}")]
UndefinedKey(String),
/// Key not found in database
#[error("{0} not found")]
NotFound(Cow<'static, str>),
/// Error originating constructing blockchain structures
#[error(transparent)]
Blockchain(#[from] CreateTipsetError),
/// Error originating from encoding arbitrary data
#[error("{0}")]
Encoding(String),
/// Error originating from Cid creation
#[error(transparent)]
Cid(#[from] CidErr),
/// Amt error
#[error("State error: {0}")]
State(Cow<'static, str>),
/// Other chain error
#[error("{0}")]
Other(String),
}
impl From<EncErr> for Error {
fn from(e: EncErr) -> Error {
Error::Encoding(e.to_string())
}
}
impl From<AmtErr> for Error {
fn from(e: AmtErr) -> Error {
Error::state(e.to_string())
}
}
impl From<String> for Error {
fn from(e: String) -> Self {
Error::Other(e)
}
}
impl From<anyhow::Error> for Error {
fn from(e: anyhow::Error) -> Self {
Error::Other(e.to_string())
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error::Other(e.to_string())
}
}
impl<T> From<flume::SendError<T>> for Error {
fn from(e: flume::SendError<T>) -> Self {
Error::Other(e.to_string())
}
}
impl Error {
pub fn state(msg: impl Into<Cow<'static, str>>) -> Self {
Self::State(msg.into())
}
}