Skip to content

Commit

Permalink
Fix RPC error code conflict (paritytech#14315)
Browse files Browse the repository at this point in the history
* Base error code module

* Base error code module

* fmt
  • Loading branch information
arkpar authored Jun 9, 2023
1 parent 83bf140 commit db3d3e8
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/rpc-api/src/author/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub enum Error {
}

/// Base code for all authorship errors.
const BASE_ERROR: i32 = 1000;
const BASE_ERROR: i32 = crate::error::base::AUTHOR;
/// Extrinsic has an invalid format.
const BAD_FORMAT: i32 = BASE_ERROR + 1;
/// Error during transaction verification in runtime.
Expand Down
2 changes: 1 addition & 1 deletion client/rpc-api/src/chain/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub enum Error {
}

/// Base error code for all chain errors.
const BASE_ERROR: i32 = 3000;
const BASE_ERROR: i32 = crate::error::base::CHAIN;

impl From<Error> for JsonRpseeError {
fn from(e: Error) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion client/rpc-api/src/dev/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub enum Error {
}

/// Base error code for all dev errors.
const BASE_ERROR: i32 = 6000;
const BASE_ERROR: i32 = crate::error::base::DEV;

impl From<Error> for JsonRpseeError {
fn from(e: Error) -> Self {
Expand Down
28 changes: 28 additions & 0 deletions client/rpc-api/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

/// Base error code for RPC modules.
pub mod base {
pub const AUTHOR: i32 = 1000;
pub const SYSTEM: i32 = 2000;
pub const CHAIN: i32 = 3000;
pub const STATE: i32 = 4000;
pub const OFFCHAIN: i32 = 5000;
pub const DEV: i32 = 6000;
pub const STATEMENT: i32 = 7000;
}
1 change: 1 addition & 0 deletions client/rpc-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#![warn(missing_docs)]

mod error;
mod policy;

pub use policy::DenyUnsafe;
Expand Down
2 changes: 1 addition & 1 deletion client/rpc-api/src/offchain/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum Error {
}

/// Base error code for all offchain errors.
const BASE_ERROR: i32 = 5000;
const BASE_ERROR: i32 = crate::error::base::OFFCHAIN;

impl From<Error> for JsonRpseeError {
fn from(e: Error) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion client/rpc-api/src/state/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub enum Error {
}

/// Base code for all state errors.
const BASE_ERROR: i32 = 4000;
const BASE_ERROR: i32 = crate::error::base::STATE;

impl From<Error> for JsonRpseeError {
fn from(e: Error) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion client/rpc-api/src/statement/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum Error {
}

/// Base error code for all statement errors.
const BASE_ERROR: i32 = 6000;
const BASE_ERROR: i32 = crate::error::base::STATEMENT;

impl From<Error> for JsonRpseeError {
fn from(e: Error) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion client/rpc-api/src/system/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub enum Error {
}

// Base code for all system errors.
const BASE_ERROR: i32 = 2000;
const BASE_ERROR: i32 = crate::error::base::SYSTEM;
// Provided block range couldn't be resolved to a list of blocks.
const NOT_HEALTHY_ERROR: i32 = BASE_ERROR + 1;
// Peer argument is malformatted.
Expand Down

0 comments on commit db3d3e8

Please sign in to comment.