{"record":{"id":"38e083663edff167","repo":"juanfont/headscale","slug":"creating-preauthkey-w","errorCode":null,"errorMessage":"creating preauthkey: %w","messagePattern":"creating preauthkey: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/headscale/cli/preauthkeys.go","lineNumber":127,"sourceCode":"\n\t\texpiryTime, err := expirationFromFlag(cmd)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tuserStr := strconv.FormatUint(user, util.Base10)\n\n\t\trequest := clientv1.CreatePreAuthKeyJSONRequestBody{\n\t\t\tUser:       &userStr,\n\t\t\tReusable:   &reusable,\n\t\t\tEphemeral:  &ephemeral,\n\t\t\tAclTags:    &tags,\n\t\t\tExpiration: &expiryTime,\n\t\t}\n\n\t\tresp, err := client.CreatePreAuthKeyWithResponse(ctx, request)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"creating preauthkey: %w\", err)\n\t\t}\n\n\t\tif resp.StatusCode() != http.StatusOK {\n\t\t\treturn apiError(resp.StatusCode(), resp.ApplicationproblemJSONDefault)\n\t\t}\n\n\t\tpreAuthKey := resp.JSON200.PreAuthKey\n\n\t\treturn printOutput(cmd, preAuthKey, preAuthKey.Key)\n\t}),\n}\n\n// preAuthKeyID reads the required --id flag for preauthkey commands.\nfunc preAuthKeyID(cmd *cobra.Command) (uint64, error) {\n\tid, _ := cmd.Flags().GetUint64(\"id\")\n\tif id == 0 {\n\t\treturn 0, fmt.Errorf(\"missing --id parameter: %w\", errMissingParameter)\n\t}","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/headscale/cli/preauthkeys.go#L109-L145","documentation":"Thrown by `headscale preauthkeys create` when client.CreatePreAuthKeyWithResponse() fails at the transport level before a response arrives. The request body (user, reusable, ephemeral, aclTags, expiration) was assembled successfully; the HTTP call itself failed.","triggerScenarios":"Server unreachable, DNS failure, TLS mismatch, connection reset while posting the create request.","commonSituations":"Running the create command right as headscale restarts; API key env var pointing at a different server; firewall dropping POST bodies.","solutions":["Verify reachability of the API endpoint with curl.","Retry the command — creates are safe to retry since failure means nothing was created.","Confirm server_url and the API key in the CLI configuration.","Check reverse proxy timeouts if the server is behind one."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"resp, err := client.CreatePreAuthKeyWithResponse(ctx, request)\nif err != nil && isTransportError(err) {\n    // create is side-effectful: before retrying, list keys to confirm none was created, then retry once\n}","preventionTips":["Health-check before scripted key creation bursts.","For provisioning pipelines, tag keys with a purpose and clean up orphans after failures.","Set explicit expirations on created keys so failed-pipeline leftovers self-expire."],"tags":["network","http","cli","preauthkeys"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}