Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Better error for missing index in CRV2
  • Loading branch information
gupnik committed May 30, 2024
commit ce87ac5d6913102cb3086cd911c4f5a5603ae139
14 changes: 11 additions & 3 deletions substrate/frame/support/procedural/src/runtime/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ impl Def {

for item in items.iter_mut() {
let mut pallet_item = None;
let mut pallet_index = 0;
let mut pallet_index = None;

let mut is_item_runtime_struct = false;

let mut disable_call = false;
let mut disable_unsigned = false;
Expand All @@ -165,12 +167,13 @@ impl Def {
RuntimeAttr::Runtime(span) if runtime_struct.is_none() => {
let p = runtime_struct::RuntimeStructDef::try_from(span, item)?;
runtime_struct = Some(p);
is_item_runtime_struct = true;
},
RuntimeAttr::Derive(_, types) if runtime_types.is_none() => {
runtime_types = Some(types);
},
RuntimeAttr::PalletIndex(span, index) => {
pallet_index = index;
pallet_index = Some(index);
pallet_item = if let syn::Item::Type(item) = item {
Some(item.clone())
} else {
Expand All @@ -187,6 +190,11 @@ impl Def {
}
}

if !is_item_runtime_struct && pallet_index.is_none() {
let msg = "Missing pallet index for pallet declaration. Please add `#[runtime::pallet_index(...)]`";
return Err(syn::Error::new(item.span(), &msg))
}

if let Some(pallet_item) = pallet_item {
match *pallet_item.ty.clone() {
syn::Type::Path(ref path) => {
Expand All @@ -209,7 +217,7 @@ impl Def {
let pallet = Pallet::try_from(
item.span(),
&pallet_item,
pallet_index,
pallet_index.expect("Pallet item is present only for valid pallet index").into(),
disable_call,
disable_unsigned,
&bounds,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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::runtime]
mod runtime {
#[runtime::runtime]
#[runtime::derive(RuntimeCall)]
pub struct Runtime;

pub type System = frame_system;
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Missing pallet index for pallet declaration. Please add `#[runtime::pallet_index(...)]`
--> tests/runtime_ui/missing_pallet_index.rs:24:5
|
24 | pub type System = frame_system;
| ^^^