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
@@ -943,7 +943,7 @@ static int parse_argv(int argc, char *argv[]) {
case 'h':
return help();
default:
assert_not_reached("Unknown option");
assert_not_reached();
}
arg_node = argv[optind];
+1 -1
View File
@@ -665,7 +665,7 @@ static int parse_argv(int argc, char * const *argv) {
case '?':
return -EINVAL;
default:
assert_not_reached("Unknown option");
assert_not_reached();
}
return 1;
+2 -2
View File
@@ -501,7 +501,7 @@ static int link_config_generate_new_name(const LinkConfigContext *ctx, const Lin
(void) sd_device_get_property_value(device, "ID_NET_NAME_MAC", &new_name);
break;
default:
assert_not_reached("invalid policy");
assert_not_reached();
}
if (ifname_valid(new_name)) {
log_device_debug(device, "Policy *%s* yields \"%s\".", name_policy_to_string(policy), new_name);
@@ -569,7 +569,7 @@ static int link_config_apply_alternative_names(sd_netlink **rtnl, const LinkConf
(void) sd_device_get_property_value(device, "ID_NET_NAME_MAC", &n);
break;
default:
assert_not_reached("invalid policy");
assert_not_reached();
}
if (!isempty(n)) {
r = strv_extend(&altnames, n);
+1 -1
View File
@@ -306,7 +306,7 @@ static int set_options(int argc, char **argv,
return -1;
default:
assert_not_reached("Unknown option");
assert_not_reached();
}
if (optind < argc && !dev_specified) {
+1 -1
View File
@@ -83,7 +83,7 @@ int main(int argc, char *argv[]) {
else if (streq(argv[1], "test2"))
test2();
else
assert_not_reached("unknown command.");
assert_not_reached();
return 0;
}
+1 -1
View File
@@ -429,7 +429,7 @@ static ssize_t udev_event_subst_format(
strpcpy(&s, l, val);
break;
default:
assert_not_reached("Unknown format substitution type");
assert_not_reached();
}
return s - dest;
+4 -4
View File
@@ -1374,7 +1374,7 @@ static bool token_match_string(UdevRuleToken *token, const char *str) {
}
break;
default:
assert_not_reached("Invalid match type");
assert_not_reached();
}
return token->op == (match ? OP_MATCH : OP_NOMATCH);
@@ -1405,7 +1405,7 @@ static bool token_match_attr(UdevRuleToken *token, sd_device *dev, UdevEvent *ev
value = vbuf;
break;
default:
assert_not_reached("Invalid attribute substitution type");
assert_not_reached();
}
/* remove trailing whitespace, if not asked to match for it */
@@ -1607,7 +1607,7 @@ static int udev_rule_apply_token_to_event(
else if (streq(k, "virt"))
val = virtualization_to_string(detect_virtualization());
else
assert_not_reached("Invalid CONST key");
assert_not_reached();
return token_match_string(token, val);
}
case TK_M_TAG:
@@ -2233,7 +2233,7 @@ static int udev_rule_apply_token_to_event(
/* do nothing for events. */
break;
default:
assert_not_reached("Invalid token type");
assert_not_reached();
}
return true;
+1 -1
View File
@@ -171,7 +171,7 @@ int control_main(int argc, char *argv[], void *userdata) {
case '?':
return -EINVAL;
default:
assert_not_reached("Unknown option.");
assert_not_reached();
}
if (optind < argc)
+1 -1
View File
@@ -71,7 +71,7 @@ static int parse_argv(int argc, char *argv[]) {
case '?':
return -EINVAL;
default:
assert_not_reached("Unknown option");
assert_not_reached();
}
return 1;
+3 -3
View File
@@ -328,7 +328,7 @@ static int query_device(QueryType query, sd_device* device) {
return print_record(device);
}
assert_not_reached("unknown query type");
assert_not_reached();
return 0;
}
@@ -456,7 +456,7 @@ int info_main(int argc, char *argv[], void *userdata) {
case '?':
return -EINVAL;
default:
assert_not_reached("Unknown option");
assert_not_reached();
}
if (action == ACTION_DEVICE_ID_FILE) {
@@ -508,7 +508,7 @@ int info_main(int argc, char *argv[], void *userdata) {
else if (action == ACTION_ATTRIBUTE_WALK)
r = print_device_chain(device);
else
assert_not_reached("Unknown action");
assert_not_reached();
if (r < 0)
return r;
}
+1 -1
View File
@@ -179,7 +179,7 @@ static int parse_argv(int argc, char *argv[]) {
case '?':
return -EINVAL;
default:
assert_not_reached("Unknown option.");
assert_not_reached();
}
if (!arg_print_kernel && !arg_print_udev) {
+1 -1
View File
@@ -81,7 +81,7 @@ static int parse_argv(int argc, char *argv[]) {
case '?':
return -EINVAL;
default:
assert_not_reached("Unknown option.");
assert_not_reached();
}
}
+1 -1
View File
@@ -45,7 +45,7 @@ static int parse_argv(int argc, char *argv[]) {
case '?':
return -EINVAL;
default:
assert_not_reached("Unknown option");
assert_not_reached();
}
arg_command = argv[optind++];
+1 -1
View File
@@ -81,7 +81,7 @@ static int parse_argv(int argc, char *argv[]) {
case '?':
return -EINVAL;
default:
assert_not_reached("Unknown option");
assert_not_reached();
}
if (!argv[optind])
+2 -2
View File
@@ -416,7 +416,7 @@ int trigger_main(int argc, char *argv[], void *userdata) {
case '?':
return -EINVAL;
default:
assert_not_reached("Unknown option");
assert_not_reached();
}
}
@@ -482,7 +482,7 @@ int trigger_main(int argc, char *argv[], void *userdata) {
return log_error_errno(r, "Failed to scan devices: %m");
break;
default:
assert_not_reached("Unknown device type");
assert_not_reached();
}
r = exec_list(e, action, settle_hashmap);
+1 -1
View File
@@ -77,7 +77,7 @@ static int parse_argv(int argc, char *argv[]) {
return -EINVAL;
default:
assert_not_reached("Unhandled option");
assert_not_reached();
}
return 1; /* work to do */
+1 -1
View File
@@ -1663,7 +1663,7 @@ static int parse_argv(int argc, char *argv[]) {
case '?':
return -EINVAL;
default:
assert_not_reached("Unhandled option");
assert_not_reached();
}
}
+1 -1
View File
@@ -52,7 +52,7 @@ int main(int argc, char *argv[]) {
return -EINVAL;
default:
assert_not_reached("Unhandled option");
assert_not_reached();
}
device = argv[optind];