{"record":{"id":"99ce2559bf372b03","repo":"googleapis/mcp-toolbox","slug":"failed-to-read-object-q-in-bucket-q-w","errorCode":null,"errorMessage":"failed to read object %q in bucket %q: %w","messagePattern":"failed to read object %q in bucket %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudstorage/cloudstorage.go","lineNumber":266,"sourceCode":"func (s *Source) ReadObject(ctx context.Context, bucket, object string, offset, length int64) (map[string]any, error) {\n\tif err := s.validateBucket(bucket); err != nil {\n\t\treturn nil, err\n\t}\n\treader, err := s.client.Bucket(bucket).Object(object).NewRangeReader(ctx, offset, length)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open object %q in bucket %q: %w\", object, bucket, err)\n\t}\n\tdefer reader.Close()\n\n\tif remain := reader.Remain(); remain > defaultMaxReadBytes {\n\t\treturn nil, fmt.Errorf(\"object %q: %d bytes exceeds %d byte limit: %w\",\n\t\t\tobject, remain, defaultMaxReadBytes,\n\t\t\tcloudstoragecommon.ErrReadSizeLimitExceeded)\n\t}\n\n\tdata, err := io.ReadAll(reader)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read object %q in bucket %q: %w\", object, bucket, err)\n\t}\n\n\tif !utf8.Valid(data) {\n\t\treturn nil, fmt.Errorf(\"object %q in bucket %q: %w\", object, bucket,\n\t\t\tcloudstoragecommon.ErrBinaryContent)\n\t}\n\n\treturn map[string]any{\n\t\t\"content\":     string(data),\n\t\t\"contentType\": reader.Attrs.ContentType,\n\t\t\"size\":        len(data),\n\t}, nil\n}\n\n// ListBuckets lists buckets in a project. When project is empty, the source's\n// configured project is used. maxResults == 0 returns up to the GCS per-page\n// default (1000). A non-empty pageToken resumes listing. The returned map\n// contains \"buckets\" ([]*storage.BucketAttrs) and \"nextPageToken\" (empty when","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudstorage/cloudstorage.go#L248-L284","documentation":"io.ReadAll failed while streaming the object body after it was opened successfully. The wrapped error is usually a network interruption mid-read, a context cancellation/deadline, or an integrity/checksum mismatch reported by the GCS client.","triggerScenarios":"ReadObject on an object where the connection drops mid-transfer, the context is cancelled (client timeout, server shutdown), or the GCS client detects a corrupted response (CRC mismatch).","commonSituations":"Long reads over flaky networks or mobile/VPN links; server-side request timeouts shorter than download duration on huge objects; context deadlines from the MCP client expiring during transfer.","solutions":["Retry the read with exponential backoff; transient network drops are usually recoverable.","Extend the context timeout / remove premature cancellation so the full read can complete.","Reduce the amount read per call (smaller offset/length ranges) to shorten each transfer.","If errors persist with checksum/integrity messages, verify the object isn't being mutated mid-read and check proxy/LB idle timeouts."],"exampleFix":"// before\nctx := context.Background()\nres, err := source.ReadObject(ctx, \"bkt\", \"obj\", 0, -1) // cancelled mid-read\n// after\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)\ndefer cancel()\nres, err := source.ReadObject(ctx, \"bkt\", \"obj\", 0, -1) // retry once on transient err","handlingStrategy":"retry","validationCode":"ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)\ndefer cancel()","typeGuard":null,"tryCatchPattern":"if errors.Is(ctx.Err(), context.DeadlineExceeded) || errors.Is(ctx.Err(), context.Canceled) {\n    // extend timeout / reschedule\n}\n// otherwise retry the read with exponential backoff","preventionTips":["Set generous context timeouts for object reads.","Read in smaller ranges so a single transfer completes quickly.","Avoid mutating objects while reading them.","Check proxy/LB idle-timeout settings for long transfers."],"tags":["network","io","read-object","gcs","cloudstorage"],"backgroundTag":"network-read-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}