1use thiserror::Error;
2
3use cosmwasm_std as cw;
4
5pub type TestResult = anyhow::Result<()>;
7
8pub type NibiruResult<T> = Result<T, NibiruError>;
9
10#[derive(Error, Debug, PartialEq)]
11pub enum NibiruError {
12 #[error("{0}")]
13 CwStd(#[from] cw::StdError),
14
15 #[error("no prost::Name implementation for type {}, where prost::Name.type_url() is needed.", type_name)]
16 NoTypeUrl { type_name: String },
17
18 #[error("prost::Name::type_url {} does not correspond to a QueryRequest::Stargate path.", type_url)]
19 ProstNameisNotQuery { type_url: String },
20
21 #[error("prost::Name::type_url {} does not correspond to a CosmosMsg::Stargate type_url.", type_url)]
22 ProstNameisNotMsg { type_url: String },
23
24 #[error("{0}")]
25 MathError(#[from] MathError),
26}
27
28#[derive(Error, Debug, PartialEq)]
29pub enum MathError {
30 #[error("division by zero not well defined")]
31 DivisionByZero,
32
33 #[error("could not parse decimal from string \"{}\": {}", dec_str, err)]
34 CwDecParseError { dec_str: String, err: cw::StdError },
35
36 #[error("could not parse to cosmosdk.io/math.LegacyDec: {0}")]
37 SdkDecError(String),
38}
39
40impl From<NibiruError> for cw::StdError {
41 fn from(err: NibiruError) -> cw::StdError {
42 match err {
43 NibiruError::CwStd(e) => e,
44 e => cw::StdError::generic_err(e.to_string()),
45 }
46 }
47}