{"record":{"id":"9ff687bb45707084","repo":"cloudflare/cloudflared","slug":"error-serializing-cidr-into-json","errorCode":null,"errorMessage":"error serializing CIDR into JSON","messagePattern":"error serializing CIDR into JSON","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cfapi/ip_route.go","lineNumber":44,"sourceCode":"\tVNetID    *uuid.UUID `json:\"virtual_network_id,omitempty\"`\n\tComment   string     `json:\"comment\"`\n\tCreatedAt time.Time  `json:\"created_at\"`\n\tDeletedAt time.Time  `json:\"deleted_at\"`\n}\n\n// CIDR is just a newtype wrapper around net.IPNet. It adds JSON unmarshalling.\ntype CIDR net.IPNet\n\nfunc (c CIDR) String() string {\n\tn := net.IPNet(c)\n\treturn n.String()\n}\n\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)","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cfapi/ip_route.go#L26-L62","documentation":"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.","triggerScenarios":"Thrown at cfapi/ip_route.go:44 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the route/CIDR value being serialized for corruption.","Retrying the request is reasonable since the cause is not input-dependent.","Report as a bug if reproducible — json.Marshal of a plain string cannot normally fail."],"exampleFix":null,"handlingStrategy":"try-catch","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-14T00:17:10.932Z"}