hasura/graphql-engine · error
error opening file: %w
Error message
error opening file: %w
What it means
While assembling seed SQL in explicit-file mode, ApplySeedsToDatabase reads each listed file with afero.ReadFile; this error wraps any read failure. The %w chain preserves the underlying cause, almost always 'no such file or directory' or 'permission denied'.
Source
Thrown at cli/seed/apply.go:70
if len(source.Name) == 0 {
return hasura.SourceKindPG
}
return source.Kind
}
var sqlAsBytes [][]byte
if len(filenames) > 0 {
for _, filename := range filenames {
absFilename := filepath.Join(seedsDirectory, filename)
if err := hasAllowedSeedFileExtensions(absFilename); err != nil {
return errors.E(op, err)
}
b, err := afero.ReadFile(fs, absFilename)
if err != nil {
return errors.E(op, fmt.Errorf("error opening file: %w", err))
}
sqlAsBytes = append(sqlAsBytes, b)
}
} else {
err := afero.Walk(fs, seedsDirectory, func(path string, file os.FileInfo, err error) error {
if file == nil || err != nil {
return errors.E(op, err)
}
if err := hasAllowedSeedFileExtensions(file.Name()); err == nil && !file.IsDir() {
b, err := afero.ReadFile(fs, path)
if err != nil {
return errors.E(op, fmt.Errorf("error opening file: %w", err))
}
sqlAsBytes = append(sqlAsBytes, b)
}View on GitHub (pinned to 724551b9ae)
Solutions
- Verify the file exists at the exact path passed (it is converted to absolute): ls -l <path>.
- Run the command from the project root so relative paths resolve as expected, or pass absolute paths.
- Fix read permissions: chmod +r file or chown $USER file.
- Remove directories from the file list — only regular files can be read.
Example fix
# before hasura seed apply --file seeds/01_init.sql # typo'd name # error opening file: open seeds/01_init.sql: no such file or directory # after ls seeds/ # confirm actual name hasura seed apply --file seeds/01-init.sql
Defensive patterns
Strategy: validation
Validate before calling
for _, f := range files {
abs, _ := filepath.Abs(f)
if fi, err := os.Stat(abs); err != nil || fi.IsDir() {
return fmt.Errorf("seed file %s missing or not a regular file", f)
}
}
// then call ApplySeedsToDatabase Try / catch
if err := seed.ApplyOnSource(...); err != nil {
var pathErr *os.PathError
if errors.As(err, &pathErr) && errors.Is(pathErr, fs.ErrNotExist) {
// missing file: correct the list and retry
}
} Prevention
- Pass absolute seed file paths or run from the project root.
- Script a pre-check that every --file argument exists before invoking the CLI.
When it happens
Trigger: Calling ApplySeedsToDatabase (via ApplyOnSource or `hasura seed apply`) with a filename in the explicit list that does not exist, is a directory, or is unreadable by the current user.
Common situations: Passing a relative seed filename that is resolved against an unexpected working directory; a typo in the filename on the command line; or seed files owned by another user/root preventing read access.
Related errors
- getting list of seed files to move: %w
- error walking the directory path: %w
- creating metadata file %s failed: %w
- getting list of migrations to move: %w
- creating target seeds directory: %w
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/0d82ff733d7927b2.
Report an issue: GitHub.