caddyserver/caddy · error

cannot invoke named route '%s', which was not defined

Error message

cannot invoke named route '%s', which was not defined

What it means

Error "cannot invoke named route '%s', which was not defined" thrown in caddyserver/caddy.

Source

Thrown at caddyconfig/httpcaddyfile/httptype.go:758

		for _, sblock := range p.serverBlocks {
			if len(sblock.pile[namedRouteKey]) == 0 {
				continue
			}
			for _, value := range sblock.pile[namedRouteKey] {
				if srv.NamedRoutes == nil {
					srv.NamedRoutes = map[string]*caddyhttp.Route{}
				}
				// named routes may invoke other named routes, so
				// resolve the set of invoked names transitively
				names := []string{value.Value.(string)}
				for len(names) > 0 {
					name := names[0]
					names = names[1:]
					if _, ok := srv.NamedRoutes[name]; ok {
						continue
					}
					if configuredNamedRoutes[name] == nil {
						return nil, fmt.Errorf("cannot invoke named route '%s', which was not defined", name)
					}
					srv.NamedRoutes[name] = configuredNamedRoutes[name]
					names = append(names, namedRouteInvokes[name]...)
				}
			}
		}

		// create a subroute for each site in the server block
		for _, sblock := range p.serverBlocks {
			matcherSetsEnc, err := st.compileEncodedMatcherSets(sblock)
			if err != nil {
				return nil, fmt.Errorf("server block %v: compiling matcher sets: %v", sblock.block.Keys, err)
			}

			hosts := sblock.hostsFromKeys(false)

			// emit warnings if user put unspecified IP addresses; they probably want the bind directive
			for _, h := range hosts {

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Define the named route before invoking it, or fix the name used in the 'invoke' directive to match a defined named route.

When it happens

Trigger: Thrown at caddyconfig/httpcaddyfile/httptype.go:758 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/f093997c8a04058d. Report an issue: GitHub.