cayleygraph/cayley · error
could not open file %q: %v
Error message
could not open file %q: %v
What it means
QuadReaderFor resolves a data path, which may be a local file path or a URL. For local paths, it opens the file with os.Open; if the open fails for a reason other than not-exist (e.g. permission denied, is a directory), the error is wrapped as this message with the path and cause.
Source
Thrown at internal/load.go:60
func QuadReaderFor(path, typ string) (quad.ReadCloser, error) {
var (
r io.Reader
c io.Closer
)
if path == "-" {
r = os.Stdin
} else if u, err := url.Parse(path); err != nil || u.Scheme == "file" || u.Scheme == "" {
// Don't alter relative URL path or non-URL path parameter.
if u.Scheme != "" && err == nil {
// Recovery heuristic for mistyping "file://path/to/file".
path = filepath.Join(u.Host, u.Path)
}
f, err := os.Open(path)
if os.IsNotExist(err) {
return nil, err
} else if err != nil {
return nil, fmt.Errorf("could not open file %q: %v", path, err)
}
r, c = f, f
} else {
res, err := http.Get(path)
if err != nil {
return nil, fmt.Errorf("could not get resource <%s>: %v", u, err)
}
// TODO(dennwc): save content type for format auto-detection
r, c = res.Body, res.Body
}
r, err := decompressor.New(r)
if err != nil {
if c != nil {
c.Close()
}
if err == io.EOF {
return nopCloser{quad.NewReader(nil)}, nilView on GitHub (pinned to 81dcd7d73e)
Solutions
- Check the wrapped cause to distinguish permission-denied vs is-a-directory
- Verify the path points to a readable regular file (ls -l)
- Run the process as a user with read permission or fix file permissions (chmod/chown)
- If the file truly doesn't exist, expect the raw os.ErrNotExist instead of this wrapper
Example fix
// before ./cayley load --data /etc/cayley # directory, not a file // after ./cayley load --data /etc/cayley/quads.nq
Defensive patterns
Strategy: validation
Validate before calling
info, err := os.Stat(path)
if err != nil { return err }
if info.IsDir() { return fmt.Errorf("%s is a directory", path) }
if info.Mode().Perm()&0o400 == 0 { return fmt.Errorf("%s not readable", path) } Try / catch
r, err := internal.QuadReaderFor(ctx, path)
if err != nil && strings.Contains(err.Error(), "could not open file") {
// fix permissions/path and retry
} Prevention
- Point loaders at regular files, not directories
- Check file permissions for the runtime user
- Prefer absolute paths in configuration
When it happens
Trigger: Loading a quad file via a file:// URL or plain path where os.Open returns a non-NotExist error: unreadable permissions, path is a directory, I/O error.
Common situations: Running Cayley as a user without read access to the data file; pointing --data at a directory instead of a file; SELinux/app restrictions on file access.
Understand the failure class
Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.
Related errors
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/bdf0f65432088a4f.
Report an issue: GitHub.