pallet_ismp/errors.rs
1// Copyright (c) 2025 Polytope Labs.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Pallet error definitions and conversions
17use polkadot_sdk::*;
18
19use alloc::string::ToString;
20use codec::{Decode, DecodeWithMemTracking, Encode};
21use sp_core::ConstU32;
22use sp_runtime::BoundedVec;
23use sp_std::prelude::*;
24
25#[derive(
26 Clone, Debug, Encode, Decode, DecodeWithMemTracking, scale_info::TypeInfo, PartialEq, Eq,
27)]
28#[allow(missing_docs)]
29pub struct HandlingError {
30 message: BoundedVec<u8, ConstU32<1000>>,
31}
32
33impl From<anyhow::Error> for HandlingError {
34 fn from(value: anyhow::Error) -> Self {
35 let mut message = value.to_string().as_bytes().to_vec();
36 message.truncate(1000);
37 Self { message: message.try_into().unwrap_or_default() }
38 }
39}