-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frame pallet macro: fix span for error on wrong returned type. (#5580)
Explicitly give the types in some generated code so that the error shows up good when user code is wrong. --------- Co-authored-by: Bastian Köcher <[email protected]> (cherry picked from commit aec2b10)
- Loading branch information
1 parent
38945d0
commit 60e37da
Showing
6 changed files
with
125 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
||
title: Fix error message on pallet macro | ||
|
||
doc: | ||
- audience: Runtime Dev | ||
description: | | ||
Improve error message for pallet macro generated code. | ||
|
||
crates: | ||
- name: frame-support-procedural | ||
bump: patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
substrate/frame/support/test/tests/pallet_ui/call_span_for_error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#[frame_support::pallet(dev_mode)] | ||
mod pallet { | ||
use frame_support::pallet_prelude::*; | ||
use frame_system::pallet_prelude::*; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config {} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::call] | ||
impl <T: Config> Pallet<T> { | ||
pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo { | ||
return Err(DispatchError::BadOrigin); | ||
} | ||
} | ||
} | ||
|
||
fn main() {} |
26 changes: 26 additions & 0 deletions
26
substrate/frame/support/test/tests/pallet_ui/call_span_for_error.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error[E0308]: mismatched types | ||
--> tests/pallet_ui/call_span_for_error.rs:32:15 | ||
| | ||
32 | return Err(DispatchError::BadOrigin); | ||
| --- ^^^^^^^^^^^^^^^^^^^^^^^^ expected `DispatchErrorWithPostInfo<PostDispatchInfo>`, found `DispatchError` | ||
| | | ||
| arguments to this enum variant are incorrect | ||
| | ||
= note: expected struct `DispatchErrorWithPostInfo<PostDispatchInfo>` | ||
found enum `frame_support::pallet_prelude::DispatchError` | ||
help: the type constructed contains `frame_support::pallet_prelude::DispatchError` due to the type of the argument passed | ||
--> tests/pallet_ui/call_span_for_error.rs:32:11 | ||
| | ||
32 | return Err(DispatchError::BadOrigin); | ||
| ^^^^------------------------^ | ||
| | | ||
| this argument influences the type of `Err` | ||
note: tuple variant defined here | ||
--> $RUST/core/src/result.rs | ||
| | ||
| Err(#[stable(feature = "rust1", since = "1.0.0")] E), | ||
| ^^^ | ||
help: call `Into::into` on this expression to convert `frame_support::pallet_prelude::DispatchError` into `DispatchErrorWithPostInfo<PostDispatchInfo>` | ||
| | ||
32 | return Err(DispatchError::BadOrigin.into()); | ||
| +++++++ |