{"record":{"id":"df7cb0482521bb3c","repo":"crowdsecurity/crowdsec","slug":"could-not-encode-jwt-auth-body-w","errorCode":null,"errorMessage":"could not encode jwt auth body: %w","messagePattern":"could not encode jwt auth body: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apiclient/auth_jwt.go","lineNumber":70,"sourceCode":"\t\tlog.Debugf(\"scenarios list updated for '%s'\", *t.MachineID)\n\t}\n\n\tauth := models.WatcherAuthRequest{\n\t\tMachineID: t.MachineID,\n\t\tPassword:  t.Password,\n\t\tScenarios: t.Scenarios,\n\t}\n\n\t/*\n\t\twe don't use the main client, so let's build the body\n\t*/\n\tvar buf io.ReadWriter = &bytes.Buffer{}\n\tenc := json.NewEncoder(buf)\n\tenc.SetEscapeHTML(false)\n\n\terr = enc.Encode(auth)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not encode jwt auth body: %w\", err)\n\t}\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf(\"%s%s/watchers/login\", t.URL, t.VersionPrefix), buf)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not create request: %w\", err)\n\t}\n\n\treq.Header.Add(\"Content-Type\", \"application/json\")\n\n\ttransport := t.Transport\n\tif transport == nil {\n\t\ttransport = http.DefaultTransport\n\t}\n\n\tclient := &http.Client{\n\t\tTransport: &retryRoundTripper{\n\t\t\tnext:             transport,\n\t\t\tmaxAttempts:      5,","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/apiclient/auth_jwt.go#L52-L88","documentation":"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.","triggerScenarios":"Thrown at pkg/apiclient/auth_jwt.go:70 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry; this indicates an internal serialization failure","Report a bug if reproducible"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}