Add a couple of throws for bad states#2132
Conversation
85c2fb7 to
f4bee14
Compare
|
@Orvid has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
| if (::write(fd, &sigNum, 1) != 1) { | ||
| throw std::runtime_error("Failed to write all the byes."); | ||
| } |
There was a problem hiding this comment.
This looks like the type of write that is infallible, i.e., cannot fail (as long as the inputs are correct), and total, i.e. cannot be a partial write.
And if this write wre to fail, there is nothing that would know how to clean this up.
Failure would be an invariant violation. If we are looking for invariant violations, such as we might do in debug builds, we would use something in the family of assert (eg DCHECK, PCHECK, FOLLY_SAFE_DCHECK, etc).
Partial writes may occur if the backend has insufficient resources to accept the full write, and if the write is non-blocking or is interrupted by a signal while blocking. But this is not the sort of write where the backend could have insufficient resources.
| default: | ||
| throw std::invalid_argument("Code '" + std::to_string(static_cast<int>(code)) + "' had no string representation!"); |
There was a problem hiding this comment.
IMO this should not be an error - it's for diagnostics.
We should like to return "(unknown)" in case of an unrecognized input. But we should also like the compiler to warn us when the cases in the switch are non-exhaustive.
Note that both of these fix a compilation warning.