{"record":{"id":"ab25f3b8fa23f2ae","repo":"apache/beam","slug":"error-getting-metadata-for-object-s-v","errorCode":null,"errorMessage":"error getting metadata for object %s: %v","messagePattern":"error getting metadata for object (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/filesystem/s3/s3.go","lineNumber":184,"sourceCode":"\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),\n\t\tKey:    aws.String(key),\n\t}\n\toutput, err := f.client.HeadObject(ctx, params)\n\tif err != nil {\n\t\treturn time.Time{}, fmt.Errorf(\"error getting metadata for object %s: %v\", filename, err)\n\t}\n\n\treturn aws.ToTime(output.LastModified), err\n}\n\n// Remove removes the file from the filesystem.\nfunc (f *fs) Remove(ctx context.Context, filename string) error {\n\tbucket, key, err := parseURI(filename)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error parsing S3 uri %s: %v\", filename, err)\n\t}\n\n\tparams := &s3.DeleteObjectInput{\n\t\tBucket: aws.String(bucket),\n\t\tKey:    aws.String(key),\n\t}\n\tif _, err = f.client.DeleteObject(ctx, params); err != nil {\n\t\treturn fmt.Errorf(\"error deleting object %s: %v\", filename, err)","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/filesystem/s3/s3.go#L166-L202","documentation":"This error is returned by the S3 filesystem's LastModified method when the AWS SDK HeadObject call fails to fetch object metadata. It wraps the underlying AWS error with the full filename for context. It means the object could not be found, is inaccessible, or the S3 request itself failed.","triggerScenarios":"Calling fs.LastModified(ctx, filename) when the bucket/key does not exist, the caller lacks s3:HeadObject permission, the region is wrong, or the AWS credentials are missing/expired.","commonSituations":"Checking a file before reading it when the object was deleted by another process; typo'd bucket or key; IAM policy missing s3:HeadObject; misconfigured AWS_REGION; expired session credentials in CI.","solutions":["Verify the object exists (correct bucket and key, no typos) via the AWS console or `aws s3 ls`.","Check IAM permissions: the credentials must allow s3:HeadObject on the bucket/key.","Confirm AWS credentials and region configuration (env vars, ~/.aws, or SDK config).","Inspect the wrapped cause (%v) for specific codes like NotFound, AccessDenied, or NoCredentialProviders and fix accordingly."],"exampleFix":"// before: assuming object exists\nlastModified, err := fsys.LastModified(ctx, \"s3://my-bucket/data/2026/output.txt\")\n\n// after: parse/verify URI and handle missing object\nif !strings.HasPrefix(filename, \"s3://\") { return fmt.Errorf(\"not an s3 path: %s\", filename) }\nlastModified, err := fsys.LastModified(ctx, filename)\nif err != nil {\n    var nfe *types.NotFound\n    if errors.As(err, &nfe) { return nil } // treat as absent\n    return err\n}","handlingStrategy":"try-catch","validationCode":"if !strings.HasPrefix(filename, \"s3://\") { return fmt.Errorf(\"not an s3 URI: %s\", filename) }\nbucket, key, err := parseS3URI(filename)\nif err != nil { return err }\n_, err = s3Client.HeadObject(ctx, &s3.HeadObjectInput{Bucket: aws.String(bucket), Key: aws.String(key)})\nif err != nil { /* object likely absent or inaccessible */ }","typeGuard":"func isS3Path(p string) bool { return strings.HasPrefix(p, \"s3://\") && len(strings.TrimPrefix(p, \"s3://\")) > 0 }","tryCatchPattern":"t, err := fsys.LastModified(ctx, filename)\nif err != nil {\n    var nfe *types.NotFound\n    if errors.As(err, &nfe) { return nil, ErrObjectAbsent }\n    if strings.Contains(err.Error(), \"AccessDenied\") { return nil, ErrPermission }\n    return fmt.Errorf(\"LastModified(%s): %w\", filename, err)\n}","preventionTips":["Check object existence (or use ListObjectsV2 prefix checks) before metadata calls.","Provision s3:HeadObject permission alongside read permissions in IAM policies.","Pin AWS region and credentials in worker environment configuration.","Prefer errors.As/As on the wrapped AWS error types over string matching."],"tags":["aws","s3","network","storage"],"backgroundTag":"http-error-response","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}