Skip to content

Add a couple of throws for bad states#2132

Open
r-barnes wants to merge 1 commit into
facebook:mainfrom
r-barnes:richard/fixes
Open

Add a couple of throws for bad states#2132
r-barnes wants to merge 1 commit into
facebook:mainfrom
r-barnes:richard/fixes

Conversation

@r-barnes

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

Copy link
Copy Markdown
Contributor

Note that both of these fix a compilation warning.

@facebook-github-bot

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

3 participants