{"record":{"id":"8d0d143fbb1a08d9","repo":"juanfont/headscale","slug":"creating-preauth-key-with-tags-w","errorCode":null,"errorMessage":"creating preauth key with tags: %w","messagePattern":"creating preauth key with tags: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"integration/scenario.go","lineNumber":562,"sourceCode":"\tkey, err := headscale.CreateAuthKeyWithOptions(opts)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating preauth key with options: %w\", err)\n\t}\n\n\treturn key, nil\n}\n\n// CreatePreAuthKeyWithTags creates a \"pre authorised key\" with the specified tags\n// to be created in the Headscale instance on behalf of the [Scenario].\nfunc (s *Scenario) CreatePreAuthKeyWithTags(\n\tuser uint64,\n\treusable bool,\n\tephemeral bool,\n\ttags []string,\n) (*clientv1.PreAuthKey, error) {\n\theadscale, err := s.Headscale()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating preauth key with tags: %w\", errNoHeadscaleAvailable)\n\t}\n\n\tkey, err := headscale.CreateAuthKeyWithTags(user, reusable, ephemeral, tags)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating preauth key with tags: %w\", err)\n\t}\n\n\treturn key, nil\n}\n\n// CreateUser creates a [User] to be created in the\n// Headscale instance on behalf of the [Scenario].\nfunc (s *Scenario) CreateUser(user string) (*clientv1.User, error) {\n\tif headscale, err := s.Headscale(); err == nil { //nolint:noinlineerr\n\t\tu, err := headscale.CreateUser(user)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"creating user: %w\", err)\n\t\t}","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/integration/scenario.go#L544-L580","documentation":"Returned by Scenario.CreatePreAuthKeyWithTags at the pre-check: no headscale control server is available (errNoHeadscaleAvailable) because s.Headscale() failed. The key-with-tags variant can never reach the gRPC layer without a running control server.","triggerScenarios":"Calling CreatePreAuthKeyWithTags when the headscale container never started or was already torn down.","commonSituations":"Earlier Scenario.Headscale() failure being masked; calling the helper after Shutdown; test running without the hi-managed Docker environment.","solutions":["Diagnose headscale startup: inspect the error from scenario.Headscale() and `docker logs` of the control container","Run tests through `go run ./cmd/hi run \"TestName\"` so the Docker environment is prepared","Ensure the call happens during the scenario's live phase, not after teardown"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if _, err := scenario.Headscale(); err != nil {\n    t.Fatalf(\"control server unavailable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"key, err := scenario.CreatePreAuthKeyWithTags(u.Id, false, false, tags)\nif err != nil {\n    t.Fatalf(\"preauth key with tags failed: %v\", err)\n}","preventionTips":["Ensure the control server is up before requesting tagged keys","Pre-authorize tags in the test policy so the gRPC layer can accept them"],"tags":["preauth-key","tags","headscale","integration-test"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}