{"record":{"id":"2d265c925bd6108f","repo":"clockworklabs/SpacetimeDB","slug":"router-registration-failed-s","errorCode":null,"errorMessage":"Router registration failed: %s\n","messagePattern":"Router registration failed: (.+?)\n","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/bindings-cpp/include/spacetimedb/router.h","lineNumber":99,"sourceCode":"    }\n\n    Router merge(const Router& other) const {\n        Router merged = *this;\n        for (const auto& route : other.routes_) {\n            merged = merged.add_route(route.method, route.path, route.handler_name);\n        }\n        return merged;\n    }\n\n    const std::vector<RouteSpec>& routes() const {\n        return routes_;\n    }\n\nprivate:\n    std::vector<RouteSpec> routes_;\n\n    [[noreturn]] static void fail_router_registration(const std::string& message) {\n        std::fprintf(stderr, \"Router registration failed: %s\\n\", message.c_str());\n        std::abort();\n    }\n\n    static bool character_is_acceptable_for_route_path(char c) {\n        return (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' || c == '_' || c == '~' || c == '/';\n    }\n\n    static void assert_valid_path(const std::string& path) {\n        if (!path.empty() && path[0] != '/') {\n            fail_router_registration(\"Route paths must start with `/`: \" + path);\n        }\n        for (char c : path) {\n            if (!character_is_acceptable_for_route_path(c)) {\n                fail_router_registration(\"Route paths may contain only ASCII lowercase letters, digits and `-_~/`: \" + path);\n            }\n        }\n    }\n","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-cpp/include/spacetimedb/router.h#L81-L117","documentation":"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.","triggerScenarios":"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\".","commonSituations":"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.","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"],"exampleFix":"// before\nauto r = Router().get(\"/Users/:id\", get_user);\n\n// after (literal paths, lowercase only)\nauto r = Router().get(\"/users\", list_users);","handlingStrategy":"validation","validationCode":"static bool valid_route_path(const std::string& p) {\n    if (!p.empty() && p[0] != '/') return false;\n    for (char c : p) {\n        bool ok = (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')\n                  || c == '-' || c == '_' || c == '~' || c == '/';\n        if (!ok) return false;\n    }\n    return true;\n}\n// unit test over the final route table\nfor (const auto& spec : router.routes()) {\n    assert(valid_route_path(spec.path));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["spacetimedb","cpp","router","http","route-registration","abort"],"backgroundTag":"invalid-route-path","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}