clockworklabs/SpacetimeDB · critical
Router registration failed
Error message
Router registration failed: %s
What it means
Fatal start-up check inside the SpacetimeDB C++ Router (unstable HTTP feature, requires SPACETIMEDB_UNSTABLE_FEATURES). fail_router_registration() is reached from assert_valid_path(), duplicate-route detection in add_route(), and nest()'s overlap check; it prints the reason to stderr and calls std::abort(), so the module process dies during preinit/publish. There is no exception to catch - the only defense is valid route tables.
Solutions
- Fix the path named in the message: it must start with '/' and contain only lowercase a-z, 0-9, '-', '_', '~', '/' (e.g. "/users", not "/Users/:id")
- Remove ':param' path segments - this router matches literal paths only; pass variables as query parameters or register one route per concrete path
- Deduplicate the method+path pair reported by the message; if routes come from merge(), check both Router instances for the same route
- For nest(), ensure the parent router has no routes under the nest prefix before nesting, or pick a different prefix
Example fix
// before
auto r = Router().get("/Users/:id", get_user);
// after (literal paths, lowercase only)
auto r = Router().get("/users", list_users); Defensive patterns
Strategy: validation
Validate before calling
static bool valid_route_path(const std::string& p) {
if (!p.empty() && p[0] != '/') return false;
for (char c : p) {
bool ok = (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')
|| c == '-' || c == '_' || c == '~' || c == '/';
if (!ok) return false;
}
return true;
}
// unit test over the final route table
for (const auto& spec : router.routes()) {
assert(valid_route_path(spec.path));
} Prevention
- Centralize route strings in one constants header so casing and characters are lintable in review
- Add a unit test that walks Router::routes() asserting path validity and no duplicate method+path pairs before publishing
- Treat route tables as compile-time config: build them from constexpr literal segments, never from unchecked runtime input
When it happens
Trigger: Router::get("users", h) with no leading '/'; a path containing characters outside [a-z0-9-_~/] such as "/Users/:id" (uppercase letters and ':' are rejected); registering the same HTTP method + path twice, including via Router::merge(); calling router.nest("/api", sub) when existing routes already start with "/api".
Common situations: Porting Express/Actix-style route tables that use ':param' segments or CamelCase paths; merging routers authored by different teams that both define "/"; pasting route strings from an OpenAPI spec without lowercasing them.
Related errors
- ERROR: HTTP handler must be registered before it is…
- ERROR: Invalid http handler ID %u (have %zu handlers)\n
- cannot deserialize refs without a typespace
- Cannot nest router at
- Cannot nest router at
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/2d265c925bd6108f.
Report an issue: GitHub.
Appendix: source
Thrown at crates/bindings-cpp/include/spacetimedb/router.h:99
}
Router merge(const Router& other) const {
Router merged = *this;
for (const auto& route : other.routes_) {
merged = merged.add_route(route.method, route.path, route.handler_name);
}
return merged;
}
const std::vector<RouteSpec>& routes() const {
return routes_;
}
private:
std::vector<RouteSpec> routes_;
[[noreturn]] static void fail_router_registration(const std::string& message) {
std::fprintf(stderr, "Router registration failed: %s\n", message.c_str());
std::abort();
}
static bool character_is_acceptable_for_route_path(char c) {
return (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' || c == '_' || c == '~' || c == '/';
}
static void assert_valid_path(const std::string& path) {
if (!path.empty() && path[0] != '/') {
fail_router_registration("Route paths must start with `/`: " + path);
}
for (char c : path) {
if (!character_is_acceptable_for_route_path(c)) {
fail_router_registration("Route paths may contain only ASCII lowercase letters, digits and `-_~/`: " + path);
}
}
}
View on GitHub (pinned to 6dee26c6ef)