clockworklabs/SpacetimeDB · error · ArgumentException

HTTP router references unknown handler

Error message

HTTP router references unknown handler `{route.HandlerFunction}`

What it means

SpacetimeDB's C# Module.RegisterHttpRouter validates each HTTP route before registering it: every route must point at a handler function that actually exists in the module definition (moduleDef.HasHttpHandler). If a route's HandlerFunction name does not match any registered HTTP handler, the router is rejected with this ArgumentException and no routes are registered.

Solutions

  1. Check each route.HandlerFunction name against the handlers your module defines and fix the mismatched name
  2. Register or un-decorate the missing handler so HasHttpHandler returns true for every route
  3. Regenerate/rebuild the router from the current module definitions so route names match the code
  4. Verify module initialization order: handlers must be registered on moduleDef before RegisterHttpRouter is called

Example fix

// before
var router = Router.WithRoute("users", HandlerFunction: "GetUserLegacy");
Module.RegisterHttpRouter(router); // throws: unknown handler `GetUserLegacy`
// after
var router = Router.WithRoute("users", HandlerFunction: "GetUser");
Module.RegisterHttpRouter(router);
Defensive patterns

Strategy: validation

Validate before calling

foreach (var route in router.GetRoutes())
{
    if (!moduleDef.HasHttpHandler(route.HandlerFunction))
        throw new InvalidOperationException(
            $"Route '{route.Name}' references undefined handler '{route.HandlerFunction}'");
}
Module.RegisterHttpRouter(router);

Type guard

static bool HasKnownHandler(ModuleDef def, string handler) =>
    !string.IsNullOrWhiteSpace(handler) && def.HasHttpHandler(handler);

Try / catch

try
{
    Module.RegisterHttpRouter(router);
}
catch (ArgumentException ex) when (ex.Message.Contains("unknown handler"))
{
    logger.LogError(ex, "HTTP router references a handler not defined in the module");
}

Prevention

When it happens

Trigger: Calling Module.RegisterHttpRouter(router) where router.GetRoutes() yields a route whose HandlerFunction string has no matching handler in the module — e.g. the handler was renamed, deleted, never decorated/registered, or the route table was built against an older module schema.

Common situations: Renaming a handler method without updating the route table; typos in the handler name; route definitions generated or deserialized from config that drifted from the actual module code; version mismatch between route registration code and module handlers.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@eddf9f5014 (2026-09-06). Data as JSON: /api/errors/507e80bc7e94e986. Report an issue: GitHub.

Appendix: source

Thrown at crates/bindings-csharp/Runtime/Internal/Module.cs:396

    {
        var procedure = ProcedureCache<P>.Instance;
        moduleDef.RegisterProcedure(procedure.MakeProcedureDef(typeRegistrar));
    }

    public static void RegisterHttpHandler<H>()
        where H : IHttpHandler, new()
    {
        var handler = HttpHandlerCache<H>.Instance;
        moduleDef.RegisterHttpHandler(handler.MakeHandlerDef());
    }

    public static void RegisterHttpRouter(SpacetimeDB.Router router)
    {
        foreach (var route in router.GetRoutes())
        {
            if (!moduleDef.HasHttpHandler(route.HandlerFunction))
            {
                throw new ArgumentException(
                    $"HTTP router references unknown handler `{route.HandlerFunction}`",
                    nameof(router)
                );
            }

            moduleDef.RegisterHttpRoute(
                new RawHttpRouteDefV10(
                    HandlerFunction: route.HandlerFunction,
                    Method: route.Method,
                    Path: route.Path
                )
            );
        }
    }

    public static void RegisterTable<T, View>()
        where T : IStructuralReadWrite, new()
        where View : ITableView<View, T>, new()

View on GitHub (pinned to eddf9f5014)