plandex-ai/plandex · error

error marshalling auth header: %v

Error message

error marshalling auth header: %v

What it means

After building a shared.AuthHeader from the loaded auth, SetAuthHeader marshals it to JSON. This error wraps any failure from json.Marshal on that struct. In practice this is nearly impossible for the plain AuthHeader struct, so it almost always indicates a corrupted or hostile in-memory auth state rather than user configuration.

Source

Thrown at app/cli/auth/api.go:35

	apiClient = client
}

func SetAuthHeader(req *http.Request) error {
	if Current == nil {
		return fmt.Errorf("error setting auth header: auth not loaded")
	}
	hash := Current.ToHash()

	authHeader := shared.AuthHeader{
		Token: Current.Token,
		OrgId: Current.OrgId,
		Hash:  hash,
	}

	bytes, err := json.Marshal(authHeader)

	if err != nil {
		return fmt.Errorf("error marshalling auth header: %v", err)
	}

	// base64 encode
	token := base64.URLEncoding.EncodeToString(bytes)

	req.Header.Set("Authorization", "Bearer "+token)

	return nil
}

func SetVersionHeader(req *http.Request) {
	req.Header.Set("X-Client-Version", version.Version)
}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Rebuild with the stock plandex-shared version to ensure AuthHeader contains only serializable fields
  2. Re-authenticate to regenerate Current from a fresh sign-in
  3. Report as a bug with the wrapped inner error (%v) if reproducible

Example fix

// before
bytes, err := json.Marshal(authHeader)
if err != nil { return fmt.Errorf("error marshalling auth header: %v", err) }
// after
bytes, err := json.Marshal(shared.AuthHeader{Token: Current.Token, OrgId: Current.OrgId, Hash: Current.ToHash()})
if err != nil { return fmt.Errorf("error marshalling auth header: %v (token=%d bytes org=%s)", err, len(Current.Token), Current.OrgId) }
Defensive patterns

Strategy: try-catch

Validate before calling

if auth.Current == nil || auth.Current.Token == "" {
	return fmt.Errorf("no valid auth to marshal")
}

Type guard

func marshalableAuth(a *shared.ClientAuth) bool { return a != nil && json.Valid([]byte(fmt.Sprintf("%v", a.Token))) }

Try / catch

if err := auth.SetAuthHeader(req); err != nil {
	if strings.Contains(err.Error(), "marshalling") {
		// treat as corrupt auth state: re-authenticate
		auth.MustResolveAuth(false)
		return auth.SetAuthHeader(req)
	}
	return err
}

Prevention

When it happens

Trigger: json.Marshal(authHeader) returns an error — realistically only if unsupported values (channels, funcs, cycles) were injected into the auth struct, since all AuthHeader fields are JSON-encodable primitives.

Common situations: Memory corruption or a modified build of plandex-shared that added non-serializable fields to AuthHeader; custom middleware mutating the request context; essentially never seen in normal usage.

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/58fdfad9443855eb. Report an issue: GitHub.