As is well documented, require
is preferred over assert
for error conditions, eg. Difference between require and assert and the difference between revert and throw
Solidity might someday include the option to include error text in a require statement. (https://solidity.readthedocs.io/en/develop/control-structures.html#error-handling-assert-require-revert-and-exceptions)
However for the time being, revert
/require
results in the unhelpful message Error: VM Exception while processing transaction: revert
, without even a line number.
One pattern involves events:
event Status(uint indexed statusCode);
...
if(someCondition) {
Status('code');
return;
}
And the error code can be extracted from the transaction logs.
Another pattern using require
:
if(someCondition) {
Status('code');
require(someCondition);
}
Or:
if(someCondition) {
Status('code');
revert();
}
Are all of these functionally identical? Is there a best practice?