caddyserver/caddy · error

setting up CEL environment

Error message

setting up CEL environment: %v

What it means

Wrapper in MatchExpression.Provision for cel.NewEnv failure: the CEL environment (placeholder function, httpRequest variable, custom type adapter, ext libraries, and matcher macro library) could not be constructed. This is an internal setup failure, usually caused by a bad extension library configuration; the wrapped error carries the CEL cause.

Solutions

  1. Simplify the CEL expression and check the wrapped error; the CEL environment failed to be configured.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at modules/caddyhttp/celmatcher.go:180 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/f0c09c773da84c6e. Report an issue: GitHub.

Appendix: source

Thrown at modules/caddyhttp/celmatcher.go:180

	matcherLib := cel.Lib(NewMatcherCELLibrary(matcherEnvOpts, matcherProgramOpts))

	// create the CEL environment
	env, err := cel.NewEnv(
		cel.Function(CELPlaceholderFuncName, cel.SingletonBinaryBinding(m.caddyPlaceholderFunc), cel.Overload(
			CELPlaceholderFuncName+"_httpRequest_string",
			[]*cel.Type{httpRequestObjectType, cel.StringType},
			cel.AnyType,
		)),
		cel.Variable(CELRequestVarName, httpRequestObjectType),
		cel.CustomTypeAdapter(m.ta),
		ext.Strings(),
		ext.Bindings(),
		ext.Lists(),
		ext.Math(),
		matcherLib,
	)
	if err != nil {
		return fmt.Errorf("setting up CEL environment: %v", err)
	}

	// parse and type-check the expression
	checked, issues := env.Compile(m.expandedExpr)
	if issues.Err() != nil {
		return fmt.Errorf("compiling CEL program: %s", issues.Err())
	}

	// request matching is a boolean operation, so we don't really know
	// what to do if the expression returns a non-boolean type
	if checked.OutputType() != cel.BoolType {
		return fmt.Errorf("CEL request matcher expects return type of bool, not %s", checked.OutputType())
	}

	// compile the "program"
	m.prg, err = env.Program(checked, cel.EvalOptions(cel.OptOptimize))
	if err != nil {
		return fmt.Errorf("compiling CEL program: %s", err)

View on GitHub (pinned to 50e54ee279)