Hi folks!
We've been working on detecting and reporting DCHECK and NOTREACHED failures in the wild as well as strengthening NOTREACHEDs to detect bugs in production. To support this work we need stronger language in the style guide.
None of these macros are appropriate for things that occasionally fail within our control, and it's preferable to CHECK over DCHECK where there are no performance concerns. CHECK failures are no longer expensive if the conditional is inexpensive to evaluate (base::ImmediateCrash() is two instructions).
Proposed changes include:
"All invariant failures should be seen as P1 bugs, regardless of their crash rate."
// Good:
//
// Testing pointer equality is very cheap, write this as a CHECK. Like many
// CHECKs, a security bug happens afterward if the CHECK would fail, in this
// case immediately afterward.
auto it = container.find(key);
CHECK(it != container.end());
*it = Foo();
We also mention alternatives to these macros as
base::ImmediateCrash() for intentionally crashing (but not invariant failure) and
base::debug::DumpWithoutCrashing(),
LOG(DFATAL) or
DLOG(FATAL) for production-non-fatal alternatives.
The style-guide change is up for review
crrev.com/c/4287020.
Please let me know what you think. :)
Peter