{"record":{"id":"ec25f87d48f1f3bc","repo":"apache/beam","slug":"error-getting-metadata-for-object-s-w","errorCode":null,"errorMessage":"error getting metadata for object %s: %w","messagePattern":"error getting metadata for object (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/filesystem/s3/s3.go","lineNumber":161,"sourceCode":"\t}\n\n\treturn newWriter(ctx, f.client, bucket, key), nil\n}\n\n// Size returns the size of the file.\nfunc (f *fs) Size(ctx context.Context, filename string) (int64, error) {\n\tbucket, key, err := parseURI(filename)\n\tif err != nil {\n\t\treturn -1, fmt.Errorf(\"error parsing S3 uri %s: %w\", filename, err)\n\t}\n\n\tparams := &s3.HeadObjectInput{\n\t\tBucket: aws.String(bucket),\n\t\tKey:    aws.String(key),\n\t}\n\toutput, err := f.client.HeadObject(ctx, params)\n\tif err != nil {\n\t\treturn -1, fmt.Errorf(\"error getting metadata for object %s: %w\", filename, err)\n\t}\n\n\tif output.ContentLength != nil {\n\t\treturn *output.ContentLength, nil\n\t}\n\n\treturn -1, fmt.Errorf(\"content length for object %s was nil\", filename)\n}\n\n// LastModified returns the time at which the file was last modified.\nfunc (f *fs) LastModified(ctx context.Context, filename string) (time.Time, error) {\n\tbucket, key, err := parseURI(filename)\n\tif err != nil {\n\t\treturn time.Time{}, fmt.Errorf(\"error parsing S3 uri %s: %v\", filename, err)\n\t}\n\n\tparams := &s3.HeadObjectInput{\n\t\tBucket: aws.String(bucket),","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/filesystem/s3/s3.go#L143-L179","documentation":"Size issues a HeadObject request to fetch ContentLength and wraps any HeadObject failure with this message (using %w for unwrapping). The URI parsed fine but the metadata request failed — typically object not found, access denied, wrong region, or network error. Size returns -1 with this error.","triggerScenarios":"Calling Size on s3://bucket/key where HeadObject returns NoSuchKey/NoSuchBucket/403/404, credentials lack s3:GetObject (HeadObject requires it), or a network failure occurs.","commonSituations":"Sizing inputs that were later deleted or renamed; region mismatch between client and bucket; IAM policies granting ListBucket but not GetObject; intermittent network faults in long-running workers.","solutions":["Verify the object exists and the key is exact (case-sensitive).","Check IAM allows s3:GetObject/HeadObject on the key.","Align the client region with the bucket region.","Retry transient network failures with backoff; inspect the wrapped AWS error code."],"exampleFix":"// before\nn, err := fs.Size(ctx, uri) // assume success\n// after\nn, err := fs.Size(ctx, uri)\nif err != nil {\n  var ae smithy.APIError\n  if errors.As(err, &ae) && ae.ErrorCode() == \"NotFound\" {\n    // handle missing object\n  }\n}","handlingStrategy":"retry","validationCode":"// verify readability before requesting size\n_, err := f.client.HeadObject(ctx, &s3.HeadObjectInput{Bucket: aws.String(b), Key: aws.String(k)})\nif err != nil { return fmt.Errorf(\"cannot stat s3://%s/%s: %w\", b, k, err) }","typeGuard":null,"tryCatchPattern":"n, err := fs.Size(ctx, uri)\nif err != nil {\n  var ae smithy.APIError\n  if errors.As(err, &ae) {\n    switch ae.ErrorCode() {\n    case \"NotFound\", \"NoSuchKey\": return 0, fmt.Errorf(\"object missing: %s\", uri)\n    default:\n      if strings.Contains(ae.Error(), \"throttl\") { return retryWithBackoff(ctx) }\n    }\n  }\n  return 0, err\n}","preventionTips":["Check object existence with HeadObject before size queries.","Ensure IAM grants s3:GetObject (needed for HeadObject).","Configure SDK retries for transient/throttling errors.","Keep client region aligned with the bucket."],"tags":["aws","s3","network","metadata"],"backgroundTag":"resource-not-found","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}