AlexxIT/go2rtc · error

expr: result is empty

Error message

expr: result is empty

What it means

The expr stream source evaluates a user expression to produce a stream URL. After evaluation, if the expression result is an empty string, there is no URL to open, so the library returns this error rather than attempting to open an empty URL.

Solutions

  1. Ensure the expression always returns a non-empty URL string (add a default branch)
  2. Log/debug the expression inputs; check the debug line '[expr] url=' to see what was produced
  3. Fix whatever data the expression depends on (env var, config value, API response)
  4. Wrap the expression so it returns a fallback URL instead of empty

Example fix

// before
streams:
  cam: expr:'getURL()'
// after
streams:
  cam: expr:'u := getURL(); if u == "" { u = "rtsp://fallback/stream" }; u'
Defensive patterns

Strategy: validation

Validate before calling

u := evalExpr(expr)
if u == "" { return errors.New("expression returned empty url") }

Type guard

func nonEmpty(s any) bool { v, ok := s.(string); return ok && v != "" }

Try / catch

url, err := tryOpen(src); if err != nil && err.Error() == "expr: result is empty" { url = fallbackURL }

Prevention

When it happens

Trigger: A stream source like expr:... whose expression evaluates to "" — e.g. a lookup/template that returns nothing, a condition that matches no branch, or an empty environment/config value the expression reads.

Common situations: Dynamic URL scripts returning empty when a camera is offline or credentials are missing; regex/template producing no match; expr function referencing an unset variable.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/e8d22cb9a87719fc. Report an issue: GitHub.

Appendix: source

Thrown at internal/expr/expr.go:23

	"github.com/AlexxIT/go2rtc/internal/app"
	"github.com/AlexxIT/go2rtc/internal/streams"
	"github.com/AlexxIT/go2rtc/pkg/expr"
)

func Init() {
	log := app.GetLogger("expr")

	streams.RedirectFunc("expr", func(url string) (string, error) {
		v, err := expr.Eval(url[5:], nil)
		if err != nil {
			return "", err
		}

		log.Debug().Msgf("[expr] url=%s", url)

		if url = v.(string); url == "" {
			return "", errors.New("expr: result is empty")
		}

		return url, nil
	})
	streams.MarkInsecure("expr")
}

View on GitHub (pinned to c245815e75)