{"record":{"id":"1434316e45f73d09","repo":"juanfont/headscale","slug":"missing-id-parameter-w","errorCode":null,"errorMessage":"missing --id parameter: %w","messagePattern":"missing --id parameter: %w","errorType":"validation","errorClass":"errMissingParameter","httpStatus":null,"severity":"error","filePath":"cmd/headscale/cli/preauthkeys.go","lineNumber":144,"sourceCode":"\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}\n\n\treturn id, nil\n}\n\nvar expirePreAuthKeyCmd = &cobra.Command{\n\tUse:     cmdExpire,\n\tShort:   \"Expire a preauthkey\",\n\tAliases: []string{\"revoke\", aliasExp, \"e\"},\n\tRunE: clientRunE(func(ctx context.Context, client *clientv1.ClientWithResponses, cmd *cobra.Command, args []string) error {\n\t\tid, err := preAuthKeyID(cmd)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tidStr := strconv.FormatUint(id, util.Base10)\n\n\t\tresp, err := client.ExpirePreAuthKeyWithResponse(ctx, clientv1.ExpirePreAuthKeyJSONRequestBody{","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/headscale/cli/preauthkeys.go#L126-L162","documentation":"Thrown by preAuthKeyID() when the --id flag is absent or zero for preauthkey expire/delete commands. It wraps the sentinel errMissingParameter. Note it is a flag-presence check: id 0 is treated as missing because headscale ids start at 1.","triggerScenarios":"`headscale preauthkeys expire` without --id, or with --id 0. Affects both expire and delete subcommands.","commonSituations":"Copy-pasting from docs that omit the flag; scripting where the id variable is empty and formats to 0.","solutions":["Find the key's id first: `headscale preauthkeys list` (id column).","Pass it explicitly: `headscale preauthkeys expire --id 42`.","In scripts, fail early if the id variable is empty before invoking the CLI."],"exampleFix":"# before\nheadscale preauthkeys expire\n\n# after\nheadscale preauthkeys expire --id 42","handlingStrategy":"validation","validationCode":"func requireFlag(cmd *cobra.Command, name string) (uint64, error) {\n    id, _ := cmd.Flags().GetUint64(name)\n    if id == 0 {\n        return 0, fmt.Errorf(\"--%s is required (see `preauthkeys list`)\", name)\n    }\n    return id, nil\n}","typeGuard":null,"tryCatchPattern":"id, err := preAuthKeyID(cmd)\nif err != nil {\n    // usage error: print id list hint, exit non-zero; never guess an id\n    return err\n}","preventionTips":["In scripts, assert the id variable is non-empty before invoking the CLI.","Use `preauthkeys list -o json` to resolve ids programmatically.","Adopt the habit of checking --help output for required flags."],"tags":["cli","validation","preauthkeys"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}