Replace Assertions with Conditional Error Raising#100
Replace Assertions with Conditional Error Raising#100odudex wants to merge 5 commits intodiybitcoinhardware:masterfrom
Conversation
|
cACK, i will do some tests to it. |
| assert num_bytes <= 64 | ||
| assert num_bytes >= 16 | ||
| if num_bytes > 64: | ||
| raise ValueError("Number of bytes must be less than 64") |
There was a problem hiding this comment.
"... must not exceed 64"
or if not 16 <= num_bytes <= 64: raise ValueError("Number of bytes must be between 16 and 64") ?
|
I've carefully reviewed these changes. I didn't catch any logic errors in this pr, seems to be doing the same thing as before (except specific exceptions rather than AssertionError (maybe some projects catch these?)) I noted one wording change, where "less than 64" might better be "less than or equal to 64". |
In order to test the replace assertions with conditional error raising, specifically, in bip85 code, was added a test for `derive_entropy` method as well the failure cases described in `derive_mnemonic` and `derive_hex`.
|
Commits from this PR were merged to |
|
The last commit (which I had forgotten to add when opening the PR) is the most important, as the removed assert would disrupt the descriptor parsing logic when Embit is run with the |
|
Merged to main |
Some consider
assertsuitable only for debugging because, as when a Python script is executed with the-O(optimize) flag, allassertstatements are stripped from the code at runtime.This is particularly relevant in Android environments, where Buildozer, by default, runs with the
-Oflag enabled. As a result, important validation checks implemented with assert would be skipped entirely.We have already been using these changes in the Krux Android app for some time, and we believe adopting this approach more broadly would be beneficial.