{"record":{"id":"c268155886b324a4","repo":"cloudflare/cloudflared","slug":"error-parsing-invalid-network-from-backend","errorCode":null,"errorMessage":"error parsing invalid network from backend","messagePattern":"error parsing invalid network from backend","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cfapi/ip_route.go","lineNumber":57,"sourceCode":"\nfunc (c CIDR) MarshalJSON() ([]byte, error) {\n\tstr := c.String()\n\tjson, err := json.Marshal(str)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"error serializing CIDR into JSON\")\n\t}\n\treturn json, nil\n}\n\n// UnmarshalJSON parses a JSON string into net.IPNet\nfunc (c *CIDR) UnmarshalJSON(data []byte) error {\n\tvar s string\n\tif err := json.Unmarshal(data, &s); err != nil {\n\t\treturn errors.Wrap(err, \"error parsing cidr string\")\n\t}\n\t_, network, err := net.ParseCIDR(s)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"error parsing invalid network from backend\")\n\t}\n\tif network == nil {\n\t\treturn fmt.Errorf(\"backend returned invalid network %s\", s)\n\t}\n\t*c = CIDR(*network)\n\treturn nil\n}\n\n// NewRoute has all the parameters necessary to add a new route to the table.\ntype NewRoute struct {\n\tNetwork  net.IPNet\n\tTunnelID uuid.UUID\n\tComment  string\n\t// Optional field. If unset, backend will assume the default vnet for the account.\n\tVNetID *uuid.UUID\n}\n\n// MarshalJSON handles fields with non-JSON types (e.g. net.IPNet).","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cfapi/ip_route.go#L39-L75","documentation":"Payload validation in cfapi CIDR.UnmarshalJSON: the backend sent a string for the CIDR field, but net.ParseCIDR cannot parse it (or ParseCIDR yielded a nil network). The route data from Tunnelstore is not a valid network prefix, so the response cannot be decoded into DetailedRoute.","triggerScenarios":"Thrown at cfapi/ip_route.go:57 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Capture the offending string from the API response and check it is a valid CIDR (e.g. 1.2.3.0/24).","Confirm no proxy/middlebox is mutating the response.","Retry; persistent invalid backend data should be reported to Cloudflare."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}