referrerpolicy=no-referrer-when-downgrade

sc_rpc_spec_v2/chain_head/subscription/
error.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19use sp_blockchain::Error;
20
21/// Subscription management error.
22#[derive(Debug, thiserror::Error)]
23pub enum SubscriptionManagementError {
24	/// The subscription has exceeded the internal limits
25	/// regarding the number of pinned blocks in memory or
26	/// the number of ongoing operations.
27	#[error("Exceeded pinning or operation limits")]
28	ExceededLimits,
29	/// Error originated from the blockchain (client or backend).
30	#[error("Blockchain error {0}")]
31	Blockchain(Error),
32	/// The database does not contain a block hash.
33	#[error("Block hash is absent")]
34	BlockHashAbsent,
35	/// The database does not contain a block header.
36	#[error("Block header is absent")]
37	BlockHeaderAbsent,
38	/// The specified subscription ID is not present.
39	#[error("Subscription is absent")]
40	SubscriptionAbsent,
41	/// The unpin method was called with duplicate hashes.
42	#[error("Duplicate hashes")]
43	DuplicateHashes,
44	/// The distance between the leaves and the current finalized block is too large.
45	#[error("Distance too large")]
46	BlockDistanceTooLarge,
47	/// Custom error.
48	#[error("Subscription error {0}")]
49	Custom(String),
50}
51
52// Blockchain error does not implement `PartialEq` needed for testing.
53impl PartialEq for SubscriptionManagementError {
54	fn eq(&self, other: &SubscriptionManagementError) -> bool {
55		match (self, other) {
56			(Self::ExceededLimits, Self::ExceededLimits) |
57			// Not needed for testing.
58			(Self::Blockchain(_), Self::Blockchain(_)) |
59			(Self::BlockHashAbsent, Self::BlockHashAbsent) |
60			(Self::BlockHeaderAbsent, Self::BlockHeaderAbsent) |
61			(Self::SubscriptionAbsent, Self::SubscriptionAbsent) |
62			(Self::DuplicateHashes, Self::DuplicateHashes) => true,
63			(Self::BlockDistanceTooLarge, Self::BlockDistanceTooLarge) => true,
64			(Self::Custom(lhs), Self::Custom(rhs)) => lhs == rhs,
65			_ => false,
66		}
67	}
68}
69
70impl From<Error> for SubscriptionManagementError {
71	fn from(err: Error) -> Self {
72		SubscriptionManagementError::Blockchain(err)
73	}
74}