{"record":{"id":"40f4475b1cf2cd65","repo":"juanfont/headscale","slug":"parsing-hujson-w","errorCode":null,"errorMessage":"parsing HuJSON: %w","messagePattern":"parsing HuJSON: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hscontrol/policy/v2/types.go","lineNumber":3129,"sourceCode":"\n\t*u = SSHUser(strings.TrimSpace(s))\n\n\treturn nil\n}\n\n// unmarshalPolicy takes a byte slice and unmarshals it into a [Policy] struct.\n// In addition to unmarshalling, it will also validate the policy.\n// This is the only entrypoint of reading a policy from a file or other source.\nfunc unmarshalPolicy(b []byte) (*Policy, error) {\n\tif len(b) == 0 {\n\t\treturn nil, nil //nolint:nilnil // intentional: no policy when empty input\n\t}\n\n\tvar policy Policy\n\n\tast, err := hujson.Parse(b)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"parsing HuJSON: %w\", err)\n\t}\n\n\tast.Standardize()\n\n\tif err = json.Unmarshal(ast.Pack(), &policy, policyJSONOpts...); err != nil { //nolint:noinlineerr\n\t\tif serr, ok := errors.AsType[*json.SemanticError](err); ok {\n\t\t\tif errors.Is(serr.Err, json.ErrUnknownName) {\n\t\t\t\tptr := serr.JSONPointer\n\t\t\t\tname := ptr.LastToken()\n\n\t\t\t\treturn nil, fmt.Errorf(\"%w: %q\", ErrUnknownField, name)\n\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}","sourceCodeStart":3111,"sourceCodeEnd":3147,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/hscontrol/policy/v2/types.go#L3111-L3147","documentation":"Error \"parsing HuJSON: %w\" thrown in juanfont/headscale.","triggerScenarios":"Thrown at hscontrol/policy/v2/types.go:3129 when the library encounters an invalid state.","commonSituations":"The policy file is not valid HuJSON. Fix syntax errors (trailing commas are allowed, but malformed objects/arrays are not).","solutions":["Inspect the wrapped error for the underlying cause and correct the failing condition (parsing HuJSON); 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 HuJSON); 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"}