juanfont/headscale · error

parsing pre-auth key: %w

Error message

parsing pre-auth key: %w

What it means

"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.

Source

Thrown at cmd/dev/main.go:189

		return fmt.Errorf("parsing user: %w", err)
	}

	// Create pre-auth key.
	keyJSON, err := runHS(
		ctx, hsBin, configPath,
		"preauthkeys", "create",
		"-u", strconv.FormatUint(userID, 10),
		"--reusable",
		"-e", "24h",
		"-o", "json",
	)
	if err != nil {
		return fmt.Errorf("creating pre-auth key: %w", err)
	}

	authKey, err := extractAuthKey(keyJSON)
	if err != nil {
		return fmt.Errorf("parsing pre-auth key: %w", err)
	}

	// Print banner.
	fmt.Printf(
		`
=== Headscale Dev Environment ===
  Server:  http://127.0.0.1:%d
  Metrics: http://127.0.0.1:%d
  Debug:   http://127.0.0.1:%d/debug/ping
  Config:  %s
  State:   %s

Pre-auth key: %s

Connect nodes with mts:
  go tool mts server run                  # start mts (once, another terminal)
  go tool mts server add node1            # create a node
  go tool mts node1 up --login-server=http://127.0.0.1:%d --authkey=%s

View on GitHub (pinned to 565fd254d0)

Solutions

  1. Run the tool from the current source (`go run ./cmd/dev`) so extractor and CLI match
  2. If it persists on a clean tree, inspect `<hsBin> preauthkeys create ... -o json` output and file an issue — the schema regressed
Defensive patterns

Strategy: try-catch

Try / catch

authKey, err := extractAuthKey(keyJSON)
if err != nil {
	// schema mismatch between CLI JSON and the extractor; inspect keyJSON and update extractor
	return fmt.Errorf("parsing pre-auth key: %w", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: Reusing a previously compiled dev binary after pulling commits that changed CLI output; terminal warnings interleaved into the captured JSON.

Related errors


AI-assisted analysis of juanfont/headscale@565fd254d0 (2026-08-15). Data as JSON: /api/errors/aaba3227b4574fdc. Report an issue: GitHub.