{"record":{"id":"e3845e51654828c3","repo":"juanfont/headscale","slug":"parsing-policy-from-bytes-w","errorCode":null,"errorMessage":"parsing policy from bytes: %w","messagePattern":"parsing policy from bytes: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hscontrol/policy/v2/types.go","lineNumber":3159,"sourceCode":"\t\t\t}\n\n\t\t\t// Non-tag entries in grant.via surface as type errors on\n\t\t\t// []Tag; rephrase to the wire-compatible body.\n\t\t\tif strings.Contains(string(serr.JSONPointer), \"/via/\") {\n\t\t\t\treturn nil, ErrGrantViaNotATag\n\t\t\t}\n\n\t\t\t// Non-ASCII tag-name failures surface from Tag.Validate\n\t\t\t// at unmarshal time. Reshape to `tagOwners[\"tag:X\"]: …`.\n\t\t\tif errors.Is(serr.Err, ErrTagNameMustStartWithLetter) {\n\t\t\t\tptr := serr.JSONPointer\n\t\t\t\tname := ptr.LastToken()\n\n\t\t\t\treturn nil, fmt.Errorf(\"tagOwners[%q]: %w\", name, ErrTagNameMustStartWithLetter)\n\t\t\t}\n\t\t}\n\n\t\treturn nil, fmt.Errorf(\"parsing policy from bytes: %w\", err)\n\t}\n\n\tif err := policy.validate(); err != nil { //nolint:noinlineerr\n\t\treturn nil, err\n\t}\n\n\treturn &policy, nil\n}\n\n// validateProtocolPortCompatibility checks that only TCP, UDP, and SCTP [Protocol]s\n// can have specific ports. All other [Protocol]s should only use wildcard ports.\nfunc validateProtocolPortCompatibility(protocol Protocol, destinations []AliasWithPorts) error {\n\t// Only TCP, UDP, and SCTP support specific ports\n\tsupportsSpecificPorts := protocol == ProtocolNameTCP || protocol == ProtocolNameUDP || protocol == ProtocolNameSCTP || protocol == \"\"\n\n\tif supportsSpecificPorts {\n\t\treturn nil // No validation needed for these protocols\n\t}","sourceCodeStart":3141,"sourceCodeEnd":3177,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/hscontrol/policy/v2/types.go#L3141-L3177","documentation":"Error \"parsing policy from bytes: %w\" thrown in juanfont/headscale.","triggerScenarios":"Thrown at hscontrol/policy/v2/types.go:3159 when the library encounters an invalid state.","commonSituations":"Loading the policy from raw bytes failed. Verify the policy content is valid HuJSON and matches the expected schema.","solutions":["Inspect the wrapped error for the underlying cause and correct the failing condition (parsing policy from bytes); retry the operation after fixing the input, configuration, or environment."],"exampleFix":"Inspect the wrapped error for the underlying cause and correct the failing condition (parsing policy from bytes); retry the operation after fixing the input, configuration, or environment.","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}