{"record":{"id":"aaba3227b4574fdc","repo":"juanfont/headscale","slug":"parsing-pre-auth-key-w","errorCode":null,"errorMessage":"parsing pre-auth key: %w","messagePattern":"parsing pre-auth key: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/dev/main.go","lineNumber":189,"sourceCode":"\t\treturn fmt.Errorf(\"parsing user: %w\", err)\n\t}\n\n\t// Create pre-auth key.\n\tkeyJSON, err := runHS(\n\t\tctx, hsBin, configPath,\n\t\t\"preauthkeys\", \"create\",\n\t\t\"-u\", strconv.FormatUint(userID, 10),\n\t\t\"--reusable\",\n\t\t\"-e\", \"24h\",\n\t\t\"-o\", \"json\",\n\t)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating pre-auth key: %w\", err)\n\t}\n\n\tauthKey, err := extractAuthKey(keyJSON)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"parsing pre-auth key: %w\", err)\n\t}\n\n\t// Print banner.\n\tfmt.Printf(\n\t\t`\n=== Headscale Dev Environment ===\n  Server:  http://127.0.0.1:%d\n  Metrics: http://127.0.0.1:%d\n  Debug:   http://127.0.0.1:%d/debug/ping\n  Config:  %s\n  State:   %s\n\nPre-auth key: %s\n\nConnect nodes with mts:\n  go tool mts server run                  # start mts (once, another terminal)\n  go tool mts server add node1            # create a node\n  go tool mts node1 up --login-server=http://127.0.0.1:%d --authkey=%s","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/dev/main.go#L171-L207","documentation":"\"parsing pre-auth key: %w\" at cmd/dev/main.go:189 wraps extractAuthKey(keyJSON) in cmd/dev. The tool parses the JSON produced by `headscale preauthkeys create ... -o json` to pull out the key string printed in the final banner. Failure means the JSON was unparseable or lacked the expected key field — output/schema mismatch between the CLI and the dev tool's extractor.","triggerScenarios":"Running a stale cmd/dev binary against a tree where the preauthkeys-create JSON schema changed; the CLI emitting an error payload instead of a key record; empty output when the command was interrupted.","commonSituations":"Reusing a previously compiled dev binary after pulling commits that changed CLI output; terminal warnings interleaved into the captured JSON.","solutions":["Run the tool from the current source (`go run ./cmd/dev`) so extractor and CLI match","If it persists on a clean tree, inspect `<hsBin> preauthkeys create ... -o json` output and file an issue — the schema regressed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"authKey, err := extractAuthKey(keyJSON)\nif err != nil {\n\t// schema mismatch between CLI JSON and the extractor; inspect keyJSON and update extractor\n\treturn fmt.Errorf(\"parsing pre-auth key: %w\", err)\n}","preventionTips":["Rebuild the dev harness after pulling changes to CLI output formats","Log the raw JSON when extraction fails to speed up diagnosis"],"tags":["dev-tooling","json","parsing","version-skew"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}