Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a couple of throws for bad states #2132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

r-barnes
Copy link
Contributor

@r-barnes r-barnes commented Jan 24, 2024

Note that both of these fix a compilation warning.

@facebook-github-bot
Copy link
Contributor

@Orvid has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Comment on lines +97 to +99
if (::write(fd, &sigNum, 1) != 1) {
throw std::runtime_error("Failed to write all the byes.");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +32 to +33
default:
throw std::invalid_argument("Code '" + std::to_string(static_cast<int>(code)) + "' had no string representation!");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants