-
Notifications
You must be signed in to change notification settings - Fork 280
Expand file tree
/
Copy patherror.rs
More file actions
80 lines (61 loc) · 2.01 KB
/
error.rs
File metadata and controls
80 lines (61 loc) · 2.01 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
79
80
use super::pskt::State;
use kaspa_txscript::script_class::ScriptClass;
use thiserror::Error;
use wasm_bindgen::prelude::*;
#[derive(Error, Debug)]
pub enum Error {
#[error("{0}")]
Custom(String),
#[error("Unexpected state: {0}")]
State(String),
#[error("Expected state: {0}")]
ExpectedState(String),
#[error("Constructor argument must be a valid payload, another PSKT instance, Transaction or undefined")]
Ctor(String),
#[error("Invalid payload")]
InvalidPayload,
#[error("Transaction not finalized")]
TxNotFinalized(#[from] crate::pskt::TxNotFinalized),
#[error(transparent)]
Wasm(#[from] workflow_wasm::error::Error),
#[error("Create state is not allowed for PSKT initialized from transaction or a payload")]
CreateNotAllowed,
#[error("PSKT must be initialized with a payload or CREATE role")]
NotInitialized,
#[error("Invalid ScriptClass, expected {0}, got {1}")]
UnexpectedScriptClassError(ScriptClass, ScriptClass),
#[error(transparent)]
ConsensusClient(#[from] kaspa_consensus_client::error::Error),
#[error(transparent)]
Pskt(#[from] crate::error::Error),
#[error(transparent)]
NetworkIdError(#[from] kaspa_consensus_core::network::NetworkIdError),
#[error(transparent)]
NetworkTypeError(#[from] kaspa_consensus_core::network::NetworkTypeError),
}
impl Error {
pub fn custom<T: std::fmt::Display>(msg: T) -> Self {
Error::Custom(msg.to_string())
}
pub fn state(state: impl AsRef<State>) -> Self {
Error::State(state.as_ref().display().to_string())
}
pub fn expected_state(state: impl Into<String>) -> Self {
Error::ExpectedState(state.into())
}
}
impl From<&str> for Error {
fn from(msg: &str) -> Self {
Error::Custom(msg.to_string())
}
}
impl From<String> for Error {
fn from(msg: String) -> Self {
Error::Custom(msg)
}
}
impl From<Error> for JsValue {
fn from(err: Error) -> Self {
JsValue::from_str(&err.to_string())
}
}