{"record":{"id":"140c76eb41ad8162","repo":"googleapis/mcp-toolbox","slug":"source-bucket-cannot-be-empty-for-tool-q","errorCode":null,"errorMessage":"source_bucket cannot be empty for tool %q","messagePattern":"source_bucket cannot be empty for tool %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/cloudstorage/cloudstoragecopyobject/cloudstoragecopyobject.go","lineNumber":77,"sourceCode":"\tType              string                 `yaml:\"type\" validate:\"required\"`\n\tSource            string                 `yaml:\"source\" validate:\"required\"`\n\tAnnotations       *tools.ToolAnnotations `yaml:\"annotations,omitempty\"`\n\tSourceBucket      *string                `yaml:\"source_bucket,omitempty\"`\n\tDestinationBucket *string                `yaml:\"destination_bucket,omitempty\"`\n}\n\nvar _ tools.ToolConfig = Config{}\n\nfunc (cfg Config) ToolConfigType() string {\n\treturn resourceType\n}\n\nfunc (cfg Config) Initialize(context.Context) (tools.Tool, error) {\n\tif cfg.Description == \"\" {\n\t\treturn nil, fmt.Errorf(\"description is required for tool %q\", cfg.Name)\n\t}\n\tif cfg.SourceBucket != nil && *cfg.SourceBucket == \"\" {\n\t\treturn nil, fmt.Errorf(\"source_bucket cannot be empty for tool %q\", cfg.Name)\n\t}\n\tif cfg.DestinationBucket != nil && *cfg.DestinationBucket == \"\" {\n\t\treturn nil, fmt.Errorf(\"destination_bucket cannot be empty for tool %q\", cfg.Name)\n\t}\n\n\tsourceObjectParam := parameters.NewStringParameter(sourceObjectKey, \"Full source object name (path) within the source bucket, e.g. 'path/to/file.txt'.\")\n\tdestinationObjectParam := parameters.NewStringParameter(destinationObjectKey, \"Full destination object name (path) within the destination bucket, e.g. 'path/to/file.txt'.\")\n\tallParameters := parameters.Parameters{}\n\tif cfg.SourceBucket == nil {\n\t\tallParameters = append(allParameters, parameters.NewStringParameter(sourceBucketKey, \"Name of the Cloud Storage bucket containing the source object.\"))\n\t}\n\tallParameters = append(allParameters, sourceObjectParam)\n\tif cfg.DestinationBucket == nil {\n\t\tallParameters = append(allParameters, parameters.NewStringParameter(destinationBucketKey, \"Name of the Cloud Storage bucket to copy into.\"))\n\t}\n\tallParameters = append(allParameters, destinationObjectParam)\n\n\treturn Tool{","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/cloudstorage/cloudstoragecopyobject/cloudstoragecopyobject.go#L59-L95","documentation":"In cloud-storage-copyobject's Config.Initialize, source_bucket is an optional *string parameter. If it is provided (non-nil) but is the empty string, the config is invalid: the tool would render a parameter with a meaningless default. Initialize rejects it early with this error naming the tool.","triggerScenarios":"Setting `sourceBucket: \"\"` or `source_bucket: \"\"` in the tool config, or binding the pointer to an empty env-substituted value (e.g. ${SOURCE_BUCKET} unset and template resolved to empty).","commonSituations":"Environment variable for the bucket name not set at deploy time so the config template substitutes an empty string; YAML key present with no value (`source_bucket:`) which unmarshals to an empty string pointer.","solutions":["Set a real bucket name for source_bucket in the config, or remove the key entirely to make it a runtime parameter","Fix the unset environment variable that templated to an empty string","Add CI validation that rendered configs contain non-empty bucket names"],"exampleFix":"// before (tools.yaml)\n  sourceBucket: ${SOURCE_BUCKET}   # env unset -> \"\"\n// after\n  sourceBucket: my-source-bucket   # or omit key to prompt at invocation","handlingStrategy":"validation","validationCode":"func checkSourceBucket(name string, ptr *string) error {\n    if ptr != nil && *ptr == \"\" {\n        return fmt.Errorf(\"tool %s: source_bucket set but empty (check env var)\", name)\n    }\n    return nil\n}","typeGuard":"func hasNonEmptyBucket(p *string) bool { return p == nil || *p != \"\" }","tryCatchPattern":"tool, err := cfg.Initialize(ctx)\nif err != nil && strings.Contains(err.Error(), \"source_bucket cannot be empty\") {\n    return fmt.Errorf(\"set SOURCE_BUCKET env or remove the key: %w\", err)\n}","preventionTips":["Verify env vars used in config templates are set before server start","Omit optional bucket keys instead of writing empty values","Use ${VAR:?} style templating that fails on unset vars","Add a startup smoke test that loads all tool configs"],"tags":["config","validation","yaml","cloud-storage","env-var"],"backgroundTag":"missing-required-config-field","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"}