From eace1150f5dafda395ac8318251b8fe468cce708 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Sat, 17 Aug 2024 06:46:53 +0530 Subject: [PATCH] [auth] Improve error message for invalid recovery input --- auth/lib/core/configuration.dart | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/auth/lib/core/configuration.dart b/auth/lib/core/configuration.dart index 586a519b65..123b8f37c0 100644 --- a/auth/lib/core/configuration.dart +++ b/auth/lib/core/configuration.dart @@ -285,9 +285,20 @@ class Configuration { Future recover(String recoveryKey) async { // check if user has entered mnemonic code if (recoveryKey.contains(' ')) { - if (recoveryKey.split(' ').length != mnemonicKeyWordCount) { + final split = recoveryKey.split(' '); + if (split.length != mnemonicKeyWordCount) { + String wordThatIsFollowedByEmptySpaceInSplit = ''; + for (int i = 1; i < split.length; i++) { + String word = split[i]; + if (word.isEmpty) { + wordThatIsFollowedByEmptySpaceInSplit = + '\n\nExtra space after word "${split[i - 1]}"'; + break; + } + } throw AssertionError( - 'recovery code should have $mnemonicKeyWordCount words', + '\nRecovery code should have $mnemonicKeyWordCount words, ' + 'found ${split.length} words instead.$wordThatIsFollowedByEmptySpaceInSplit', ); } recoveryKey = bip39.mnemonicToEntropy(recoveryKey);