{"record":{"id":"3cd515601dcc2c62","repo":"charmbracelet/crush","slug":"failed-to-decode-session-history-files-w","errorCode":null,"errorMessage":"failed to decode session history files: %w","messagePattern":"failed to decode session history files: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/proto.go","lineNumber":636,"sourceCode":"\tif err := json.NewDecoder(rsp.Body).Decode(&sess); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode session: %w\", err)\n\t}\n\treturn &sess, nil\n}\n\n// ListSessionHistoryFiles retrieves history files for a session as proto types.\nfunc (c *Client) ListSessionHistoryFiles(ctx context.Context, id string, sessionID string) ([]proto.File, error) {\n\trsp, err := c.get(ctx, fmt.Sprintf(\"/workspaces/%s/sessions/%s/history\", id, sessionID), nil, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get session history files: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to get session history files: status code %d\", rsp.StatusCode)\n\t}\n\tvar files []proto.File\n\tif err := json.NewDecoder(rsp.Body).Decode(&files); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode session history files: %w\", err)\n\t}\n\treturn files, nil\n}\n\n// CreateSession creates a new session in a workspace as a proto type.\nfunc (c *Client) CreateSession(ctx context.Context, id string, title string) (*proto.Session, error) {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/sessions\", id), nil, jsonBody(proto.Session{Title: title}), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create session: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to create session: status code %d\", rsp.StatusCode)\n\t}\n\tvar sess proto.Session\n\tif err := json.NewDecoder(rsp.Body).Decode(&sess); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode session: %w\", err)\n\t}","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/proto.go#L618-L654","documentation":"ListSessionHistoryFiles got HTTP 200 but the response body could not be decoded into []proto.File. The JSON decode error is wrapped with this message. Typically the body is malformed, truncated, or shaped differently than the expected array of File objects.","triggerScenarios":"History endpoint returns 200 with a non-array JSON document, truncated body, empty body, or File fields whose types changed between server/client versions.","commonSituations":"Proxy returning 200 with HTML; server version skew changing the File schema; server returning null or an object instead of an array.","solutions":["Log the wrapped error to see the exact decode failure.","curl the endpoint and inspect the raw body to confirm the JSON shape.","Align server and client versions so the File schema matches proto.File.","Check for proxies/middleware rewriting responses.","Retry on truncated (unexpected EOF) responses."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isHistoryDecodeError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"failed to decode session history files\")\n}","tryCatchPattern":"files, err := client.ListSessionHistoryFiles(ctx, wsID, sessID)\nif err != nil {\n    if isHistoryDecodeError(err) {\n        // inspect raw server response / align versions, then retry\n        return fmt.Errorf(\"unparseable history payload: %w\", err)\n    }\n    return err\n}","preventionTips":["Match server/client schema versions.","Verify endpoint output with curl before integrating.","Beware proxies returning 200 with HTML.","Retry on unexpected-EOF truncations."],"tags":["http","json-decode","client"],"backgroundTag":"json-response-decode-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}