Drop the text argument from assert_not_reached()

In general we almost never hit those asserts in production code, so users see
them very rarely, if ever. But either way, we just need something that users
can pass to the developers.

We have quite a few of those asserts, and some have fairly nice messages, but
many are like "WTF?" or "???" or "unexpected something". The error that is
printed includes the file location, and function name. In almost all functions
there's at most one assert, so the function name alone is enough to identify
the failure for a developer. So we don't get much extra from the message, and
we might just as well drop them.

Dropping them makes our code a tiny bit smaller, and most importantly, improves
development experience by making it easy to insert such an assert in the code
without thinking how to phrase the argument.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-08-03 10:05:10 +02:00
parent c7cfde640d
commit 04499a70fb
222 changed files with 380 additions and 390 deletions
+1 -1
View File
@@ -200,7 +200,7 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
return -EINVAL;
default:
assert_not_reached("Unhandled option");
assert_not_reached();
}
if (arg_mode == _MODE_INVALID)
+3 -3
View File
@@ -3009,7 +3009,7 @@ static int compat_parse_argv(int argc, char *argv[]) {
return -EINVAL;
default:
assert_not_reached("Unhandled option");
assert_not_reached();
}
if (arg_type == 0 && arg_class != 0)
@@ -3261,7 +3261,7 @@ static int native_parse_argv(int argc, char *argv[]) {
return -EINVAL;
default:
assert_not_reached("Unhandled option");
assert_not_reached();
}
if (arg_type == 0 && arg_class != 0)
@@ -3411,7 +3411,7 @@ static int compat_main(int argc, char *argv[], sd_bus *bus) {
return translate("revert", arg_ifname, 0, NULL, bus);
case _MODE_INVALID:
assert_not_reached("invalid mode");
assert_not_reached();
}
return 0;
+1 -1
View File
@@ -135,7 +135,7 @@ static int reply_query_state(DnsQuery *q) {
case DNS_TRANSACTION_VALIDATING:
case DNS_TRANSACTION_SUCCESS:
default:
assert_not_reached("Impossible state");
assert_not_reached();
}
}
+1 -1
View File
@@ -395,7 +395,7 @@ int config_parse_dnssd_txt(
break;
default:
assert_not_reached("Unknown type of Txt config");
assert_not_reached();
}
LIST_INSERT_AFTER(items, txt_data->txt, last, i);
+1 -1
View File
@@ -1028,7 +1028,7 @@ int dnssec_verify_rrset_search(
continue;
default:
assert_not_reached("Unexpected DNSSEC validation result");
assert_not_reached();
}
}
}
+1 -1
View File
@@ -332,7 +332,7 @@ static inline size_t udp_header_size(int af) {
case AF_INET6:
return UDP6_PACKET_HEADER_SIZE;
default:
assert_not_reached("Unexpected address family");
assert_not_reached();
}
}
+1 -1
View File
@@ -757,7 +757,7 @@ DnsScopeMatch dns_scope_good_domain(
}
default:
assert_not_reached("Unknown scope protocol");
assert_not_reached();
}
}
+2 -2
View File
@@ -58,7 +58,7 @@ int dns_search_domain_new(
break;
default:
assert_not_reached("Unknown search domain type");
assert_not_reached();
}
d->linked = true;
@@ -135,7 +135,7 @@ void dns_search_domain_move_back_and_unmark(DnsSearchDomain *d) {
break;
default:
assert_not_reached("Unknown search domain type");
assert_not_reached();
}
}
+3 -3
View File
@@ -90,7 +90,7 @@ int dns_server_new(
break;
default:
assert_not_reached("Unknown server type");
assert_not_reached();
}
s->linked = true;
@@ -158,7 +158,7 @@ void dns_server_unlink(DnsServer *s) {
s->manager->n_dns_servers--;
break;
default:
assert_not_reached("Unknown server type");
assert_not_reached();
}
s->linked = false;
@@ -213,7 +213,7 @@ void dns_server_move_back_and_unmark(DnsServer *s) {
break;
default:
assert_not_reached("Unknown server type");
assert_not_reached();
}
}
+1 -1
View File
@@ -813,7 +813,7 @@ static void dns_stub_query_complete(DnsQuery *q) {
case DNS_TRANSACTION_PENDING:
case DNS_TRANSACTION_VALIDATING:
default:
assert_not_reached("Impossible state");
assert_not_reached();
}
dns_query_free(q);
+6 -6
View File
@@ -1091,7 +1091,7 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p, bool encrypt
break;
default:
assert_not_reached("Invalid DNS protocol.");
assert_not_reached();
}
if (t->received != p) {
@@ -1184,7 +1184,7 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p, bool encrypt
break;
default:
assert_not_reached("Invalid DNS protocol.");
assert_not_reached();
}
if (DNS_PACKET_TC(p)) {
@@ -1528,7 +1528,7 @@ static int on_transaction_timeout(sd_event_source *s, usec_t usec, void *userdat
break;
default:
assert_not_reached("Invalid DNS protocol.");
assert_not_reached();
}
log_debug("Timeout reached on transaction %" PRIu16 ".", t->id);
@@ -1567,7 +1567,7 @@ static usec_t transaction_get_resend_timeout(DnsTransaction *t) {
return t->scope->resend_timeout;
default:
assert_not_reached("Invalid DNS protocol.");
assert_not_reached();
}
}
@@ -1959,7 +1959,7 @@ int dns_transaction_go(DnsTransaction *t) {
accuracy = MDNS_JITTER_RANGE_USEC;
break;
default:
assert_not_reached("bad protocol");
assert_not_reached();
}
assert(!t->timeout_event_source);
@@ -3530,7 +3530,7 @@ int dns_transaction_validate_dnssec(DnsTransaction *t) {
break;
default:
assert_not_reached("Unexpected NSEC result.");
assert_not_reached();
}
}
+1 -1
View File
@@ -78,7 +78,7 @@ static int reply_query_state(DnsQuery *q) {
case DNS_TRANSACTION_VALIDATING:
case DNS_TRANSACTION_SUCCESS:
default:
assert_not_reached("Impossible state");
assert_not_reached();
}
}