1#![allow(missing_docs)]
2use std::fmt::{Display, Formatter};
3
4use crate::std::AbstractError;
5use cosmwasm_std::Addr;
6use cw_asset::AssetError;
7use thiserror::Error;
8
9#[derive(Error, Debug, PartialEq)]
11pub struct EndpointError {
12 #[source]
13 source: AbstractSdkError,
14 module_id: String,
15}
16
17impl Display for EndpointError {
18 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
19 write!(f, "Error in {} - {}", self.module_id, self.source)
20 }
21}
22
23#[derive(Error, Debug, PartialEq)]
25pub enum AbstractSdkError {
26 #[error("Abstract Account error in the sdk: {0}")]
27 Abstract(#[from] AbstractError),
28
29 #[error("Std error encountered in sdk: {0}")]
30 Std(#[from] cosmwasm_std::StdError),
31
32 #[error("Asset error encountered in sdk while handling assets: {0}")]
33 Asset(#[from] AssetError),
34
35 #[error("Missing handler for {endpoint}")]
36 MissingHandler { endpoint: String },
37
38 #[error("Missing module {module}")]
40 MissingModule { module: String },
41
42 #[error("Module {module} is not a dependency of this contract.")]
43 MissingDependency { module: String },
44
45 #[error("IBC callback called by {caller} instead of IBC client {client_addr}.")]
47 CallbackNotCalledByIbcClient {
48 caller: Addr,
49 client_addr: Addr,
50 module: String,
51 },
52
53 #[error("Module {module} Ibc Endpoint called by {caller} instead of IBC host {host_addr}.")]
55 ModuleIbcNotCalledByHost {
56 caller: Addr,
57 host_addr: Addr,
58 module: String,
59 },
60
61 #[error("Called an IBC module action on {0}, when no endpoint was registered.")]
63 NoModuleIbcHandler(String),
64
65 #[error("API query for {api} failed in {module_id}: {error}")]
67 ApiQuery {
68 api: String,
69 module_id: String,
70 error: Box<AbstractError>,
71 },
72
73 #[error("Queried address {addr} is not a module: {err}")]
75 NotAModule { addr: Addr, err: String },
76
77 #[error(
79 "Queried address {addr} is a module ({module}) but has the wrong stored address : {err}"
80 )]
81 WrongModuleInfo {
82 addr: Addr,
83 module: String,
84 err: String,
85 },
86
87 #[error(
89 "Only the admin can execute this action. An admin is either the owner of an account of an account called by its owner"
90 )]
91 OnlyAdmin {},
92}
93
94impl AbstractSdkError {
95 pub fn generic_err(msg: impl Into<String>) -> Self {
96 AbstractSdkError::Std(cosmwasm_std::StdError::generic_err(msg))
97 }
98}