From 97f74253387ee43e30c25fd970b5ae4cc1a722d7 Mon Sep 17 00:00:00 2001
From: gui <gui.thiolliere@gmail.com>
Date: Fri, 26 Apr 2024 21:27:14 +0900
Subject: [PATCH] Try state: log errors instead of loggin the number of error
 and discarding them (#4265)

Currently we discard errors content
We should at least log it.

Code now is more similar to what is written in try_on_runtime_upgrade.

label should be R0

---------

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Javier Bullrich <javier@bullrich.dev>
---
 .../support/src/traits/try_runtime/mod.rs     | 23 +++++++++++++------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/substrate/frame/support/src/traits/try_runtime/mod.rs b/substrate/frame/support/src/traits/try_runtime/mod.rs
index bec2dbf549a..c1bf1feb19e 100644
--- a/substrate/frame/support/src/traits/try_runtime/mod.rs
+++ b/substrate/frame/support/src/traits/try_runtime/mod.rs
@@ -161,22 +161,31 @@ impl<BlockNumber: Clone + sp_std::fmt::Debug + AtLeast32BitUnsigned> TryState<Bl
 		match targets {
 			Select::None => Ok(()),
 			Select::All => {
-				let mut error_count = 0;
+				let mut errors = Vec::<TryRuntimeError>::new();
+
 				for_tuples!(#(
-					if let Err(_) = Tuple::try_state(n.clone(), targets.clone()) {
-						error_count += 1;
+					if let Err(err) = Tuple::try_state(n.clone(), targets.clone()) {
+						errors.push(err);
 					}
 				)*);
 
-				if error_count > 0 {
+				if !errors.is_empty() {
 					log::error!(
 						target: "try-runtime",
-						"{} pallets exited with errors while executing try_state checks.",
-						error_count
+						"Detected errors while executing `try_state`:",
 					);
 
+					errors.iter().for_each(|err| {
+						log::error!(
+							target: "try-runtime",
+							"{:?}",
+							err
+						);
+					});
+
 					return Err(
-						"Detected errors while executing try_state checks. See logs for more info."
+						"Detected errors while executing `try_state` checks. See logs for more \
+						info."
 							.into(),
 					)
 				}
-- 
GitLab