{"record":{"id":"1d0ec84bfdf55a7d","repo":"juanfont/headscale","slug":"parsing-machine-key-w","errorCode":null,"errorMessage":"parsing machine key: %w","messagePattern":"parsing machine key: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cmd/headscale/cli/debug.go","lineNumber":43,"sourceCode":"}\n\nvar debugCmd = &cobra.Command{\n\tUse:   \"debug\",\n\tShort: \"debug and testing commands\",\n\tLong:  \"debug contains extra commands used for debugging and testing headscale\",\n}\n\nvar createNodeCmd = &cobra.Command{\n\tUse:   \"create-node\",\n\tShort: \"Create a node that can be registered with `auth register <>` command\",\n\tRunE: clientRunE(func(ctx context.Context, client *clientv1.ClientWithResponses, cmd *cobra.Command, args []string) error {\n\t\tuser, _ := cmd.Flags().GetString(\"user\")\n\t\tname, _ := cmd.Flags().GetString(\"name\")\n\t\tregistrationID, _ := cmd.Flags().GetString(\"key\")\n\n\t\t_, err := types.AuthIDFromString(registrationID)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"parsing machine key: %w\", err)\n\t\t}\n\n\t\troutes, _ := cmd.Flags().GetStringSlice(\"route\")\n\n\t\tresp, err := client.DebugCreateNodeWithResponse(ctx, clientv1.DebugCreateNodeJSONRequestBody{\n\t\t\tKey:    &registrationID,\n\t\t\tName:   &name,\n\t\t\tUser:   &user,\n\t\t\tRoutes: &routes,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"creating node: %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","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/headscale/cli/debug.go#L25-L61","documentation":"Returned by 'headscale debug create-node' when the --key flag (registration ID) cannot be parsed by types.AuthIDFromString. The registration ID has a fixed format; arbitrary strings, empty values, or wrongly copied keys fail this local validation before any server call is made.","triggerScenarios":"Passing a --key that is not a valid registration/auth ID: empty string, a machine public key (mkey:...) instead of a registration id, or a truncated/mistyped value. The check exists so the debug command fails fast without a network round trip.","commonSituations":"Test scripts generating their own key strings instead of using the format produced by the server; copy-paste of node keys; confusion between nodekey, machinekey, and registration id in the debug flow.","solutions":["Use a registration id actually issued by the server (from a pending registration or the test harness)","If generating ids in tests, mirror the format accepted by types.AuthIDFromString (read its parser)","Drop the flag entirely if the server is meant to generate one (omit --key rather than passing a placeholder"],"exampleFix":"# before\nheadscale debug create-node --name n1 --user u1 --key my-custom-key\n\n# after\nheadscale debug create-node --name n1 --user u1 --key \"$REGISTRATION_ID\"","handlingStrategy":"validation","validationCode":"if _, err := types.AuthIDFromString(registrationID); err != nil {\n\treturn fmt.Errorf(\"--key must be a valid registration id: %w\", err)\n}","typeGuard":"func validAuthID(s string) bool {\n\t_, err := types.AuthIDFromString(s)\n\treturn err == nil\n}","tryCatchPattern":null,"preventionTips":["Only use registration ids issued by the server/harness","Do not substitute machine keys or node keys for --key"],"tags":["cli","validation","debug","go"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}