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
@@ -320,7 +320,7 @@ static int acl_entry_equal(acl_entry_t a, acl_entry_t b) {
return *gid_a == *gid_b;
}
default:
assert_not_reached("Unknown acl tag type");
assert_not_reached();
}
}
+2 -2
View File
@@ -291,7 +291,7 @@ int bus_connect_transport(
break;
default:
assert_not_reached("Hmm, unknown transport type.");
assert_not_reached();
}
if (r < 0)
return r;
@@ -337,7 +337,7 @@ int bus_connect_transport_systemd(BusTransport transport, const char *host, bool
break;
default:
assert_not_reached("Hmm, unknown transport type.");
assert_not_reached();
}
return r;
+1 -1
View File
@@ -202,7 +202,7 @@ static bool test_order(int k, OrderOperator p) {
return k > 0;
default:
assert_not_reached("unknown order");
assert_not_reached();
}
}
+3 -3
View File
@@ -316,7 +316,7 @@ static size_t table_data_size(TableDataType type, const void *data) {
return sizeof(mode_t);
default:
assert_not_reached("Uh? Unexpected cell type");
assert_not_reached();
}
}
@@ -1048,7 +1048,7 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
return 0;
default:
assert_not_reached("Uh? Unexpected data type.");
assert_not_reached();
}
r = table_add_cell(t, &last_cell, type, data);
@@ -1778,7 +1778,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
default:
assert_not_reached("Unexpected type?");
assert_not_reached();
}
return d->formatted;
+3 -3
View File
@@ -2897,7 +2897,7 @@ int unit_file_lookup_state(
break;
default:
assert_not_reached("Unexpected unit file type.");
assert_not_reached();
}
*ret = state;
@@ -2989,7 +2989,7 @@ static int presets_find_config(UnitFileScope scope, const char *root_dir, char *
else if (IN_SET(scope, UNIT_FILE_GLOBAL, UNIT_FILE_USER))
dirs = user_dirs;
else
assert_not_reached("Invalid unit file scope");
assert_not_reached();
return conf_files_list_strv(files, ".preset", root_dir, 0, dirs);
}
@@ -3173,7 +3173,7 @@ static int query_presets(const char *name, const UnitFilePresets *presets, char
log_debug("Preset files say disable %s.", name);
return 0;
default:
assert_not_reached("invalid preset action");
assert_not_reached();
}
}
+1 -1
View File
@@ -417,7 +417,7 @@ int journal_importer_process_data(JournalImporter *imp) {
return 0; /* continue */
default:
assert_not_reached("wtf?");
assert_not_reached();
}
}
+6 -6
View File
@@ -505,7 +505,7 @@ static void json_variant_set(JsonVariant *a, JsonVariant *b) {
break;
default:
assert_not_reached("Unexpected variant type");
assert_not_reached();
}
}
@@ -763,7 +763,7 @@ static size_t json_variant_size(JsonVariant* v) {
return offsetof(JsonVariant, value);
default:
assert_not_reached("unexpected type");
assert_not_reached();
}
}
@@ -1397,7 +1397,7 @@ bool json_variant_equal(JsonVariant *a, JsonVariant *b) {
}
default:
assert_not_reached("Unknown variant type.");
assert_not_reached();
}
}
@@ -1749,7 +1749,7 @@ static int json_format(FILE *f, JsonVariant *v, JsonFormatFlags flags, const cha
}
default:
assert_not_reached("Unexpected variant type.");
assert_not_reached();
}
return 0;
@@ -2787,7 +2787,7 @@ int json_tokenize(
return -EINVAL;
default:
assert_not_reached("Unexpected tokenizer state");
assert_not_reached();
}
null_return:
@@ -3156,7 +3156,7 @@ static int json_parse_internal(
break;
default:
assert_not_reached("Unexpected token");
assert_not_reached();
}
if (add) {
+2 -2
View File
@@ -422,7 +422,7 @@ int local_outbounds(
break;
default:
assert_not_reached("Unexpected protocol");
assert_not_reached();
}
/* So ideally we'd just use IP_UNICAST_IF here to pass the ifindex info to the kernel before
@@ -493,7 +493,7 @@ int local_outbounds(
break;
default:
assert_not_reached("Unexpected protocol");
assert_not_reached();
}
}
+1 -1
View File
@@ -416,7 +416,7 @@ static int output_timestamp_realtime(FILE *f, sd_journal *j, OutputMode mode, Ou
break;
default:
assert_not_reached("Unknown time format");
assert_not_reached();
}
}
+1 -1
View File
@@ -76,7 +76,7 @@ int service_parse_argv(
return -EINVAL;
default:
assert_not_reached("Unknown option code.");
assert_not_reached();
}
if (optind < argc)
+1 -1
View File
@@ -129,7 +129,7 @@ int socket_address_parse(SocketAddress *a, const char *s) {
.size = sizeof(struct sockaddr_in6),
};
else
assert_not_reached("Family quarrel");
assert_not_reached();
}
}
+1 -1
View File
@@ -160,7 +160,7 @@ bool have_namespaces(void) {
if (si.si_status == EXIT_FAILURE)
return false;
assert_not_reached("unexpected exit code");
assert_not_reached();
}
bool can_memlock(void) {
+2 -2
View File
@@ -90,7 +90,7 @@ UserDBIterator* userdb_iterator_free(UserDBIterator *iterator) {
break;
default:
assert_not_reached("Unexpected state?");
assert_not_reached();
}
sd_event_unref(iterator->event);
@@ -333,7 +333,7 @@ static int userdb_on_query_reply(
}
default:
assert_not_reached("unexpected lookup");
assert_not_reached();
}
finish:
+2 -2
View File
@@ -905,7 +905,7 @@ static int varlink_dispatch_method(Varlink *v) {
break;
default:
assert_not_reached("Unexpected state");
assert_not_reached();
}
@@ -1521,7 +1521,7 @@ int varlink_call(
return varlink_log_errno(v, SYNTHETIC_ERRNO(ETIME), "Connection timed out.");
default:
assert_not_reached("Unexpected state after method call.");
assert_not_reached();
}
}
+1 -1
View File
@@ -233,5 +233,5 @@ int xml_tokenize(const char **p, char **name, void **state, unsigned *line) {
}
assert_not_reached("Bad state");
assert_not_reached();
}