{"record":{"id":"f988f076a489c639","repo":"juanfont/headscale","slug":"loading-policy-w","errorCode":null,"errorMessage":"loading policy: %w","messagePattern":"loading policy: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hscontrol/state/state.go","lineNumber":254,"sourceCode":"\tnodes, err := db.ListNodes()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"loading nodes: %w\", err)\n\t}\n\n\t// On startup, all nodes should be marked as offline until they reconnect\n\t// This ensures we don't have stale online status from previous runs\n\tfor _, node := range nodes {\n\t\tnode.IsOnline = new(false)\n\t}\n\n\tusers, err := db.ListUsers(nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"loading users: %w\", err)\n\t}\n\n\tpol, err := hsdb.PolicyBytes(db.DB, cfg)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"loading policy: %w\", err)\n\t}\n\n\tpolMan, err := policy.NewPolicyManager(pol, users, nodes.ViewSlice())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"initializing policy manager: %w\", err)\n\t}\n\n\t// Apply defaults for [NodeStore] batch configuration if not set.\n\t// This ensures tests that create Config directly (without viper) still work.\n\tbatchSize := cmp.Or(cfg.Tuning.NodeStoreBatchSize, defaultNodeStoreBatchSize)\n\n\tbatchTimeout := cmp.Or(cfg.Tuning.NodeStoreBatchTimeout, defaultNodeStoreBatchTimeout)\n\n\t// [policy.PolicyManager.BuildPeerMap] handles both global and per-node filter complexity.\n\t// This moves the complex peer relationship logic into the policy package where it belongs.\n\tnodeStore := NewNodeStore(\n\t\tnodes,\n\t\tfunc(nodes []types.NodeView) map[types.NodeID][]types.NodeView {","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/hscontrol/state/state.go#L236-L272","documentation":"Error \"loading policy: %w\" thrown in juanfont/headscale.","triggerScenarios":"Thrown at hscontrol/state/state.go:254 when the library encounters an invalid state.","commonSituations":"Loading the policy at startup failed. Validate the policy file or database-stored policy with the policy check command.","solutions":["Inspect the wrapped error for the underlying cause and correct the failing condition (loading policy); retry the operation after fixing the input, configuration, or environment."],"exampleFix":"Inspect the wrapped error for the underlying cause and correct the failing condition (loading policy); 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-15T22:17:37.221Z"}