{"record":{"id":"5eed6587d06aace9","repo":"apache/beam","slug":"size-operation-failed-localfilesystem","errorCode":null,"errorMessage":"Size operation failed","messagePattern":"Size operation failed","errorType":"exception","errorClass":"BeamIOError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/localfilesystem.py","lineNumber":279,"sourceCode":"    Returns: boolean flag indicating if path exists\n    \"\"\"\n    return os.path.exists(path)\n\n  def size(self, path):\n    \"\"\"Get size of path on the FileSystem.\n\n    Args:\n      path: string path in question.\n\n    Returns: int size of path according to the FileSystem.\n\n    Raises:\n      ``BeamIOError``: if path doesn't exist.\n    \"\"\"\n    try:\n      return os.path.getsize(path)\n    except Exception as e:  # pylint: disable=broad-except\n      raise BeamIOError(\"Size operation failed\", {path: e})\n\n  def last_updated(self, path):\n    \"\"\"Get UNIX Epoch time in seconds on the FileSystem.\n\n    Args:\n      path: string path of file.\n\n    Returns: float UNIX Epoch time\n\n    Raises:\n      ``BeamIOError``: if path doesn't exist.\n    \"\"\"\n    if not self.exists(path):\n      raise BeamIOError('Path does not exist: %s' % path)\n    return os.path.getmtime(path)\n\n  def checksum(self, path):\n    \"\"\"Fetch checksum metadata of a file on the","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/localfilesystem.py#L261-L297","documentation":"LocalFileSystem.size returns the size of a single file via os.path.getsize, and wraps any failure (missing path, path is a directory, permission error) in BeamIOError('Size operation failed', {path: original_error}). The docstring documents BeamIOError as the failure mode when the path doesn't exist. Note this method only handles single paths, not globs.","triggerScenarios":"Calling LocalFileSystem.size(path) (or FileSystems.size via matching filesystem) where os.path.getsize fails: the file does not exist, path points to a directory (getsize works but semantics differ per platform; error mainly for missing/inaccessible paths), or permission is denied.","commonSituations":"Querying the size of a not-yet-created output file; race between another process deleting the file and the size call; passing a directory path where a file path is required.","solutions":["Check existence first with FileSystems.exists(path) or os.path.exists before calling size.","Verify the path is a file, not a directory, for a file size.","Catch BeamIOError and read exception_details[path] for the root cause.","Use FileSystems.match([glob]) and read metadata_list[*].size_in_bytes when you need sizes for globs or possibly-missing files.","Add retry with backoff if the file may be transiently absent due to concurrent writes."],"exampleFix":"// before\nsize = fs.size(path)  # BeamIOError if file missing\n// after\nif fs.exists(path):\n    size = fs.size(path)\nelse:\n    size = None","handlingStrategy":"try-catch","validationCode":"import os\nif os.path.isfile(path):\n    size = os.path.getsize(path)\nelse:\n    size = None","typeGuard":null,"tryCatchPattern":"from apache_beam.io.filesystem import BeamIOError\ntry:\n    size = fs.size(path)\nexcept BeamIOError as e:\n    size = None  # or log e.exception_details[path]","preventionTips":["Check exists/isfile before querying size","For globs use FileSystems.match and read size_in_bytes from metadata instead","Add retry for files being written concurrently by other workers"],"tags":["python","apache-beam","filesystem","file-size"],"backgroundTag":"file-not-found","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"}