{"record":{"id":"fd1351913417495d","repo":"charmbracelet/crush","slug":"failed-to-set-config-field-status-code-d","errorCode":null,"errorMessage":"failed to set config field: status code %d","messagePattern":"failed to set config field: status code (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/config.go","lineNumber":26,"sourceCode":"\n\t\"github.com/charmbracelet/crush/internal/config\"\n\t\"github.com/charmbracelet/crush/internal/oauth\"\n\t\"github.com/charmbracelet/crush/internal/proto\"\n)\n\n// SetConfigField sets a config key/value pair on the server.\nfunc (c *Client) SetConfigField(ctx context.Context, id string, scope config.Scope, key string, value any) error {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/config/set\", id), nil, jsonBody(struct {\n\t\tScope config.Scope `json:\"scope\"`\n\t\tKey   string       `json:\"key\"`\n\t\tValue any          `json:\"value\"`\n\t}{Scope: scope, Key: key, Value: value}), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to set config field: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to set config field: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n\n// RemoveConfigField removes a config key on the server.\nfunc (c *Client) RemoveConfigField(ctx context.Context, id string, scope config.Scope, key string) error {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/config/remove\", id), nil, jsonBody(struct {\n\t\tScope config.Scope `json:\"scope\"`\n\t\tKey   string       `json:\"key\"`\n\t}{Scope: scope, Key: key}), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to remove config field: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to remove config field: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/config.go#L8-L44","documentation":"SetConfigField's server-rejection path: the request reached the server but the status code was not 200. Unlike other client methods this does not use checkStatus, so no sentinel (e.g. ErrNotFound) is applied.","triggerScenarios":"POST /workspaces/{id}/config/set returns any status other than 200 (e.g. 400 bad key/value, 404 unknown workspace, 500 server error).","commonSituations":"Setting a config key the server does not recognize; workspace already torn down; server-side validation rejecting the value type.","solutions":["Log the returned status code and inspect server logs for the rejection reason","Validate the key/value against supported config fields before calling","Confirm the workspace id exists before mutating its config"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate inputs before calling\nif id == \"\" {\n    return fmt.Errorf(\"workspace id is required\")\n}\nif key == \"\" {\n    return fmt.Errorf(\"config key is required\")\n}","typeGuard":null,"tryCatchPattern":"if err := c.SetConfigField(ctx, id, scope, key, value); err != nil {\n    var statusErr interface{ Error() string }\n    _ = statusErr\n    // message embeds the status code; log it and inspect server logs\n    return fmt.Errorf(\"config set rejected: %w\", err)\n}","preventionTips":["Only set keys the server recognizes","Verify the workspace exists before mutation","Match client/server versions to avoid unknown-field rejections"],"tags":["http","config","bad-request"],"backgroundTag":"http-non-200-response","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}