Skip to content
Open
Changes from all commits
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
5 changes: 3 additions & 2 deletions src/mnemonic/mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ def to_entropy(self, words: list[str] | str) -> bytearray:
wordindex = 0
for word in words:
# Find the words index in the wordlist
ndx = self.wordlist.index(self.normalize_string(word))
if ndx < 0:
try:
ndx = self.wordlist.index(self.normalize_string(word))
except ValueError:
raise LookupError('Unable to find "%s" in word list.' % word)
Comment on lines +168 to 171

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This keeps ValueError and gives the position instead of the word. Raising outside the except block also keeps the original 'abuot' is not in list out of the exception and its traceback.

Suggested change
try:
ndx = self.wordlist.index(self.normalize_string(word))
except ValueError:
raise LookupError('Unable to find "%s" in word list.' % word)
try:
ndx = self.wordlist.index(self.normalize_string(word))
except ValueError:
ndx = -1
if ndx < 0:
raise ValueError("Word %d is not in the word list." % (wordindex + 1))

# Set the next 11 bits to the value of the index.
for ii in range(11):
Expand Down