{"record":{"id":"bdf0f65432088a4f","repo":"cayleygraph/cayley","slug":"could-not-open-file-q-v","errorCode":null,"errorMessage":"could not open file %q: %v","messagePattern":"could not open file %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/load.go","lineNumber":60,"sourceCode":"\nfunc QuadReaderFor(path, typ string) (quad.ReadCloser, error) {\n\tvar (\n\t\tr io.Reader\n\t\tc io.Closer\n\t)\n\tif path == \"-\" {\n\t\tr = os.Stdin\n\t} else if u, err := url.Parse(path); err != nil || u.Scheme == \"file\" || u.Scheme == \"\" {\n\t\t// Don't alter relative URL path or non-URL path parameter.\n\t\tif u.Scheme != \"\" && err == nil {\n\t\t\t// Recovery heuristic for mistyping \"file://path/to/file\".\n\t\t\tpath = filepath.Join(u.Host, u.Path)\n\t\t}\n\t\tf, err := os.Open(path)\n\t\tif os.IsNotExist(err) {\n\t\t\treturn nil, err\n\t\t} else if err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not open file %q: %v\", path, err)\n\t\t}\n\t\tr, c = f, f\n\t} else {\n\t\tres, err := http.Get(path)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not get resource <%s>: %v\", u, err)\n\t\t}\n\t\t// TODO(dennwc): save content type for format auto-detection\n\t\tr, c = res.Body, res.Body\n\t}\n\n\tr, err := decompressor.New(r)\n\tif err != nil {\n\t\tif c != nil {\n\t\t\tc.Close()\n\t\t}\n\t\tif err == io.EOF {\n\t\t\treturn nopCloser{quad.NewReader(nil)}, nil","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/internal/load.go#L42-L78","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n./cayley load --data /etc/cayley # directory, not a file\n// after\n./cayley load --data /etc/cayley/quads.nq","handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err != nil { return err }\nif info.IsDir() { return fmt.Errorf(\"%s is a directory\", path) }\nif info.Mode().Perm()&0o400 == 0 { return fmt.Errorf(\"%s not readable\", path) }","typeGuard":null,"tryCatchPattern":"r, err := internal.QuadReaderFor(ctx, path)\nif err != nil && strings.Contains(err.Error(), \"could not open file\") {\n    // fix permissions/path and retry\n}","preventionTips":["Point loaders at regular files, not directories","Check file permissions for the runtime user","Prefer absolute paths in configuration"],"tags":["file","io","permissions"],"backgroundTag":"file-open-failed","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}