{"record":{"id":"35dba1ace7f24a1f","repo":"googleapis/mcp-toolbox","slug":"object-q-in-bucket-q-w","errorCode":null,"errorMessage":"object %q in bucket %q: %w","messagePattern":"object %q in bucket %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudstorage/cloudstorage.go","lineNumber":270,"sourceCode":"\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\n// there are no more results).\nfunc (s *Source) ListBuckets(ctx context.Context, project, prefix string, maxResults int, pageToken string) (map[string]any, error) {\n\tif project == \"\" {\n\t\tproject = s.Project","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudstorage/cloudstorage.go#L252-L288","documentation":"The object's bytes were read successfully but are not valid UTF-8, so the source rejects them by wrapping cloudstoragecommon.ErrBinaryContent. The tool returns text content only, and binary data cannot be represented in the string response.","triggerScenarios":"ReadObject on binary objects: images (PNG/JPEG), archives (zip/tar.gz), PDFs, Parquet/Avro, or any file with invalid UTF-8 sequences anywhere in the read range.","commonSituations":"LLM user asking to 'read' a .png or .zip from a bucket; listing bucket contents and reading every object without filtering by content-type; offset/length windows landing inside multibyte or binary regions of mixed-encoding files.","solutions":["Only call ReadObject on text objects; check the object's contentType (via ListObjects/metadata) is text/*, application/json, etc. first.","For binary objects, download via gsutil/the GCS client instead of this text-oriented tool.","If the file is meant to be text but fails UTF-8 validation, re-upload it after converting encoding (e.g. iconv to UTF-8).","Handle ErrBinaryContent (errors.Is) in the caller and surface a friendly 'binary content not supported' message to the user."],"exampleFix":"// before\nres, err := source.ReadObject(ctx, \"bkt\", \"images/logo.png\", 0, -1) // binary\n// after\nif isTextContentType(\"image/png\") == false { return errors.New(\"use a binary download path for this object\") }\nres, err := source.ReadObject(ctx, \"bkt\", \"notes/readme.txt\", 0, -1)","handlingStrategy":"validation","validationCode":"func isTextContentType(ct string) bool {\n    ct = strings.ToLower(ct)\n    return strings.HasPrefix(ct, \"text/\") || ct == \"application/json\" || ct == \"application/yaml\"\n}\n// check object contentType before ReadObject","typeGuard":"func isBinaryContentErr(err error) bool {\n    return errors.Is(err, cloudstoragecommon.ErrBinaryContent)\n}","tryCatchPattern":"if errors.Is(err, cloudstoragecommon.ErrBinaryContent) {\n    return nil, fmt.Errorf(\"object is binary; use a download tool instead\")\n}","preventionTips":["Filter by contentType (text/*) before reading objects.","Convert non-UTF-8 text files to UTF-8 at upload time.","Handle ErrBinaryContent explicitly to give users a clear message.","Don't bulk-read every object in a bucket; skip known binary prefixes (.png, .zip, .pdf)."],"tags":["encoding","utf8","binary-content","read-object","cloudstorage"],"backgroundTag":"binary-content-unsupported","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"}