apache/cassandra · error · IOError

Can't open %r for reading: no matching file found

Error message

Can't open %r for reading: no matching file found

What it means

Before opening files for COPY FROM, each comma-separated path is checked: if it is not a literal file, it is treated as a glob pattern; if the glob returns no matches, an IOError is raised saying no matching file was found.

Source

Thrown at pylib/cqlshlib/copyutil.py:906

        """
         Return a source generator. Each source is a named tuple
         wrapping the source input, file name and a boolean indicating
         if it requires closing.
        """
        def make_source(fname):
            try:
                return open(fname, 'r')
            except IOError as e:
                raise IOError("Can't open %r for reading: %s" % (fname, e))

        for path in paths.split(','):
            path = path.strip()
            if os.path.isfile(path):
                yield make_source(path)
            else:
                result = glob.glob(path)
                if len(result) == 0:
                    raise IOError("Can't open %r for reading: no matching file found" % (path,))

                for f in result:
                    yield make_source(f)

    def start(self):
        self.sources = self.get_source(self.fname)
        self.next_source()

    @property
    def exhausted(self):
        return not self.current_source

    def next_source(self):
        """
         Close the current source, if any, and open the next one. Return true
         if there is another source, false otherwise.
        """
        self.close_current_source()

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Verify the path/pattern with ls or glob before running COPY FROM
  2. Use an absolute path or cd to the directory containing the file first
  3. Check case sensitivity of the extension on Linux filesystems

Example fix

// before
COPY t FROM './exports/data*.csv';  # no match
// after
$ ls ./exports/
data-2026-09-01.csv
COPY t FROM './exports/data-2026-09-01.csv';
Defensive patterns

Strategy: validation

Validate before calling

import glob, os
p = '/path/data*.csv'
if not os.path.isfile(p) and not glob.glob(p):
    raise SystemExit(f"No file matches {p}")

Try / catch

try:
    run_copy_from(fname)
except IOError:
    print("No matching input file; check path/pattern and cwd")

Prevention

When it happens

Trigger: COPY FROM '/path/data*.csv' (or a plain path) where os.path.isfile(path) is false and glob.glob(path) returns an empty list — the file does not exist or the glob pattern matches nothing in the working directory.

Common situations: Typo in the filename, running cqlsh from a different working directory than expected, glob pattern with wrong extension (*.CSV vs *.csv on case-sensitive filesystems), files not yet produced by an upstream export job.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/c81b043d6d7b9fe3. Report an issue: GitHub.