Should there be unreachable code in production?
While taking a look at the coverage reports, I've found something like this:
if let Host::Hostname(addr) = &self.host {
if !is_valid_hostname(addr) {
// This ought not to occur, because it violates Host's invariant
return Err(ErrorDetail::InvalidHostname);
}
if addr.ends_with_ignore_ascii_case(HSID_ONION_SUFFIX) {
// This ought not to occur, because it violates Host's invariant
return Err(ErrorDetail::OnionAddressNotSupported);
}
}
I am a bit indifferent whether we should include such things in the code, instead of something like an assert!()
.
On one hand, this leads to a decrease in the runtime, on the other hand this makes 100% test coverage impossible.