fatedier/frp · error

failed to render template for proxy %s: %v

Error message

failed to render template for proxy %s: %v

What it means

While loading a legacy ini client config, every section named with the 'range:' prefix is expanded by renderRangeProxyTemplates into one concrete proxy section per port. This error wraps any failure of that expansion, including the port-validation errors from errors 155-157 or port-number parse failures from util.ParseRangeNumbers.

Source

Thrown at pkg/config/legacy/client.go:248

	}

	startAll := len(startProxy) == 0

	// Build template sections from range section And append to ini.File.
	rangeSections := make([]*ini.Section, 0)
	for _, section := range f.Sections() {

		if !strings.HasPrefix(section.Name(), "range:") {
			continue
		}

		rangeSections = append(rangeSections, section)
	}

	for _, section := range rangeSections {
		err = renderRangeProxyTemplates(f, section)
		if err != nil {
			return nil, nil, fmt.Errorf("failed to render template for proxy %s: %v", section.Name(), err)
		}
	}

	for _, section := range f.Sections() {
		name := section.Name()

		if name == ini.DefaultSection || name == "common" || strings.HasPrefix(name, "range:") {
			continue
		}

		_, shouldStart := startProxy[name]
		if !startAll && !shouldStart {
			continue
		}

		roleType := section.Key("role").String()
		if roleType == "" {
			roleType = "server"

View on GitHub (pinned to 6c8a8d0a97)

Solutions

  1. Read the inner error — it pinpoints empty ports, invalid numbers, or count mismatch
  2. Set both local_port and remote_port in the [range:...] section using single values, comma lists, or a-b ranges
  3. Make both sides expand to the same number of ports (equal counts of comma-separated items and ranges)
  4. Validate numbers are decimal port values with no stray characters

Example fix

; before
[range:web]
type = tcp
local_port = 6000-6002
remote_port = 7000-7001   ; count mismatch (3 vs 2)

; after
[range:web]
type = tcp
local_port = 6000-6002
remote_port = 7000-7002
Defensive patterns

Strategy: validation

Validate before calling

for _, s := range file.Sections() {
    if strings.HasPrefix(s.Name(), "range:") {
        if s.Key("local_port").String() == "" || s.Key("remote_port").String() == "" {
            return fmt.Errorf("%s: range section needs local_port and remote_port", s.Name())
        }
    }
}

Prevention

When it happens

Trigger: A [range:xxx] section where local_port/remote_port is empty, non-numeric, uses a malformed range (e.g. '2000-1000-'), has mismatched counts ('local_port = 6000-6002' with 'remote_port = 7000-7001'), or where creating the derived section fails. The %s is the range section name, e.g. 'range:web'.

Common situations: Converting a single proxy to a range and forgetting one of the two port keys; typos like '600O' instead of '6000'; assuming ranges auto-pad counts; using commas inside a dash range.

Related errors


AI-assisted analysis of fatedier/frp@6c8a8d0a97 (2026-08-15). Data as JSON: /api/errors/e63d1d8057d4da14. Report an issue: GitHub.