juanfont/headscale · error
parsing user: %w
Error message
parsing user: %w
What it means
"parsing user: %w" at cmd/dev/main.go:171 wraps extractUserID(userJSON) in cmd/dev. The tool takes the JSON emitted by `headscale users create dev -o json` and extracts the numeric user id needed for the pre-auth key step. The error means the JSON could not be parsed or lacked the expected id field — i.e. the CLI's output shape did not match what the dev tool expects.
Source
Thrown at cmd/dev/main.go:171
// Wait for server to be ready.
healthURL := fmt.Sprintf("http://127.0.0.1:%d/health", *port)
err = waitForHealth(ctx, healthURL, 30*time.Second)
if err != nil {
return fmt.Errorf("waiting for headscale: %w", err)
}
// Create user.
fmt.Println("Creating user and pre-auth key...")
userJSON, err := runHS(ctx, hsBin, configPath, "users", "create", "dev", "-o", "json")
if err != nil {
return fmt.Errorf("creating user: %w", err)
}
userID, err := extractUserID(userJSON)
if err != nil {
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)View on GitHub (pinned to 565fd254d0)
Solutions
- Rebuild/re-run the dev tool from the same source tree: `go run ./cmd/dev` (never mix old tool with new server source)
- Inspect the CLI's JSON output manually with `headscale users create dev -o json` and report a schema-change bug if the id field is genuinely missing
Defensive patterns
Strategy: try-catch
Try / catch
userID, err := extractUserID(userJSON)
if err != nil {
// version skew between dev tool and CLI output schema — rebuild both from the same tree
return fmt.Errorf("parsing user: %w", err)
} Prevention
- Always run the dev tool from the same checkout as the server: `go run ./cmd/dev`
- Treat JSON-shape changes in CLI -o json output as breaking changes for tooling
When it happens
Trigger: Running a cmd/dev binary whose runHS/extractUserID expectations differ from the users-create JSON produced by the current source tree (e.g. version skew after pulling new commits that changed the CLI output); the CLI emitted an error object or empty output instead of a user record.
Common situations: A stale compiled cmd/dev being reused after the users API output format changed; a partially written config causing the CLI to print a warning line alongside the JSON.
Related errors
- parsing pre-auth key: %w
- unmarshalling user JSON: %w (raw: %s)
- unmarshalling key JSON: %w (raw: %s)
- unknown autogroup
- type not supported
AI-assisted analysis of juanfont/headscale@565fd254d0 (2026-08-15).
Data as JSON: /api/errors/9389c53f3778f1ec.
Report an issue: GitHub.