cloudflare/cloudflared · error

error serializing CIDR into JSON

Error message

error serializing CIDR into JSON

What it means

Serialization failure in cfapi CIDR.MarshalJSON: converting the CIDR's string form into a JSON value failed. This is effectively unreachable in practice (net.IPNet.String output is always marshalable), so seeing it indicates an unusual internal state in the route struct being sent to Tunnelstore.

Source

Thrown at cfapi/ip_route.go:44

	VNetID    *uuid.UUID `json:"virtual_network_id,omitempty"`
	Comment   string     `json:"comment"`
	CreatedAt time.Time  `json:"created_at"`
	DeletedAt time.Time  `json:"deleted_at"`
}

// CIDR is just a newtype wrapper around net.IPNet. It adds JSON unmarshalling.
type CIDR net.IPNet

func (c CIDR) String() string {
	n := net.IPNet(c)
	return n.String()
}

func (c CIDR) MarshalJSON() ([]byte, error) {
	str := c.String()
	json, err := json.Marshal(str)
	if err != nil {
		return nil, errors.Wrap(err, "error serializing CIDR into JSON")
	}
	return json, nil
}

// UnmarshalJSON parses a JSON string into net.IPNet
func (c *CIDR) UnmarshalJSON(data []byte) error {
	var s string
	if err := json.Unmarshal(data, &s); err != nil {
		return errors.Wrap(err, "error parsing cidr string")
	}
	_, network, err := net.ParseCIDR(s)
	if err != nil {
		return errors.Wrap(err, "error parsing invalid network from backend")
	}
	if network == nil {
		return fmt.Errorf("backend returned invalid network %s", s)
	}
	*c = CIDR(*network)

View on GitHub (pinned to 2253eeeb25)

Solutions

  1. Inspect the route/CIDR value being serialized for corruption.
  2. Retrying the request is reasonable since the cause is not input-dependent.
  3. Report as a bug if reproducible — json.Marshal of a plain string cannot normally fail.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at cfapi/ip_route.go:44 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06). Data as JSON: /api/errors/9ff687bb45707084. Report an issue: GitHub.