fix(crypto): run ajv validator again when encountering exceptions#3008
fix(crypto): run ajv validator again when encountering exceptions#3008faustbrian merged 1 commit intodevelopfrom
Conversation
If the block validation fails and there are any exceptions, instead of continuing right away, rerun the schema validation without bailing out on the first encountered error. This ensures all bignumber properties are properly converted.
Codecov Report
@@ Coverage Diff @@
## develop #3008 +/- ##
===========================================
+ Coverage 66.06% 66.09% +0.03%
===========================================
Files 420 420
Lines 10036 10039 +3
Branches 510 511 +1
===========================================
+ Hits 6630 6635 +5
+ Misses 3364 3363 -1
+ Partials 42 41 -1
Continue to review full report at Codecov.
|
| // Validate again without bailing out on the first error to ensure that all properties get properly converted if necessary | ||
| validator.validateException("block", data); | ||
| } else { | ||
| throw new BlockSchemaError(data.height, error); |
There was a problem hiding this comment.
You can remove this, it is never going to be executed. If error is true and the long expression is false then we would have thrown already earlier.
if (A && !B) {
throw E;
}
if (A) {
if (B) {
C;
} else {
throw E; // this will never be executed
}
}
Or even better: remove the first if (lines 14-20) https://github.com/ArkEcosystem/core/pull/3008/files#diff-915b384fb6553933d473ac42c25419c2L14-L20 that code is equivalent to:
if (A) {
if (B) {
C;
} else {
throw E;
}
}
There was a problem hiding this comment.
Yes, lines 14-20 were intended to be removed.
Summary
If the block validation fails and there are any exceptions, instead of continuing right away, rerun the schema validation without bailing out on the first encountered error. This ensures all bignumber
properties are properly converted.
Fixes #3003
Checklist