prov_cosmwasm_std/errors/
system_error.rs1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use crate::Binary;
5
6#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
16#[serde(rename_all = "snake_case")]
17#[non_exhaustive]
18pub enum SystemError {
19 InvalidRequest {
20 error: String,
21 request: Binary,
22 },
23 InvalidResponse {
24 error: String,
25 response: Binary,
26 },
27 NoSuchContract {
28 addr: String,
30 },
31 Unknown {},
32 UnsupportedRequest {
33 kind: String,
34 },
35}
36
37impl std::error::Error for SystemError {}
38
39impl std::fmt::Display for SystemError {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 match self {
42 SystemError::InvalidRequest { error, request } => write!(
43 f,
44 "Cannot parse request: {} in: {}",
45 error,
46 String::from_utf8_lossy(request)
47 ),
48 SystemError::InvalidResponse { error, response } => write!(
49 f,
50 "Cannot parse response: {} in: {}",
51 error,
52 String::from_utf8_lossy(response)
53 ),
54 SystemError::NoSuchContract { addr } => write!(f, "No such contract: {}", addr),
55 SystemError::Unknown {} => write!(f, "Unknown system error"),
56 SystemError::UnsupportedRequest { kind } => {
57 write!(f, "Unsupported query type: {}", kind)
58 }
59 }
60 }
61}