crowdsecurity/crowdsec · error
could not encode jwt auth body: %w
Error message
could not encode jwt auth body: %w
What it means
Returned by refreshJwtToken when the WatcherAuthRequest body (machine id, password, scenarios) cannot be JSON-encoded before posting to /watchers/login. Wraps the encoding error from the streaming json.Encoder writing into the request buffer.
Source
Thrown at pkg/apiclient/auth_jwt.go:70
log.Debugf("scenarios list updated for '%s'", *t.MachineID)
}
auth := models.WatcherAuthRequest{
MachineID: t.MachineID,
Password: t.Password,
Scenarios: t.Scenarios,
}
/*
we don't use the main client, so let's build the body
*/
var buf io.ReadWriter = &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)
err = enc.Encode(auth)
if err != nil {
return fmt.Errorf("could not encode jwt auth body: %w", err)
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("%s%s/watchers/login", t.URL, t.VersionPrefix), buf)
if err != nil {
return fmt.Errorf("could not create request: %w", err)
}
req.Header.Add("Content-Type", "application/json")
transport := t.Transport
if transport == nil {
transport = http.DefaultTransport
}
client := &http.Client{
Transport: &retryRoundTripper{
next: transport,
maxAttempts: 5,View on GitHub (pinned to 909b515798)
Solutions
- Retry; this indicates an internal serialization failure
- Report a bug if reproducible
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at pkg/apiclient/auth_jwt.go:70 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/df7cb0482521bb3c.
Report an issue: GitHub.