{"record":{"id":"ebd38574ccf76558","repo":"apache/beam","slug":"error-parsing-s3-uri-s-w","errorCode":null,"errorMessage":"error parsing S3 uri %s: %w","messagePattern":"error parsing S3 uri (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/filesystem/s3/s3.go","lineNumber":152,"sourceCode":"\treturn output.Body, nil\n}\n\n// OpenWrite returns a new io.WriteCloser to write contents to the file. The caller must call Close\n// on the returned io.WriteCloser when done writing.\nfunc (f *fs) OpenWrite(ctx context.Context, filename string) (io.WriteCloser, error) {\n\tbucket, key, err := parseURI(filename)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error parsing S3 uri %s: %v\", filename, err)\n\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","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/filesystem/s3/s3.go#L134-L170","documentation":"Size parses the filename as an S3 URI before issuing a HeadObject; this error wraps a parseURI failure (note it uses %w so errors.Is/As unwrapping works). It indicates the filename is not a valid s3://bucket/key URI. Size returns -1 along with the error.","triggerScenarios":"Calling Size with a malformed URI: missing s3:// scheme, empty bucket or key, e.g. 's3://bucket' with no key or a bare local path.","commonSituations":"Computing input sizes for pipeline planning with paths that lost their scheme during string manipulation; local files accidentally passed to the S3 filesystem.","solutions":["Pass a valid s3://bucket/key URI to Size.","Validate/normalize URIs before calling; parseURI failures are reported via the wrapped error.","Use the filesystem provider matching the URI scheme.","Since %w is used, use errors.As to inspect the underlying parse error."],"exampleFix":"// before\nn, err := fs.Size(ctx, \"my-bucket/data/file\")\n// after\nn, err := fs.Size(ctx, \"s3://my-bucket/data/file\")","handlingStrategy":"validation","validationCode":"func validS3URI(name string) bool {\n  u, err := url.Parse(name)\n  return err == nil && u.Scheme == \"s3\" && u.Host != \"\" && strings.TrimPrefix(u.Path, \"/\") != \"\"\n}","typeGuard":null,"tryCatchPattern":"n, err := fs.Size(ctx, filename)\nif err != nil {\n  if strings.Contains(err.Error(), \"error parsing S3 uri\") {\n    return 0, fmt.Errorf(\"not an s3 uri: %s\", filename)\n  }\n  return 0, err // note %w allows errors.As unwrapping\n}","preventionTips":["Ensure URIs passed to Size are full s3://bucket/key paths.","Normalize paths in one place before any filesystem calls.","Use the provider matching the URI scheme.","Exploit the %w wrapping with errors.As for structured handling."],"tags":["s3","url","validation"],"backgroundTag":"invalid-url-format","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"}