{"record":{"id":"0d82ff733d7927b2","repo":"hasura/graphql-engine","slug":"error-opening-file-w","errorCode":null,"errorMessage":"error opening file: %w","messagePattern":"error opening file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/seed/apply.go","lineNumber":70,"sourceCode":"\t\tif len(source.Name) == 0 {\n\t\t\treturn hasura.SourceKindPG\n\t\t}\n\n\t\treturn source.Kind\n\t}\n\n\tvar sqlAsBytes [][]byte\n\n\tif len(filenames) > 0 {\n\t\tfor _, filename := range filenames {\n\t\t\tabsFilename := filepath.Join(seedsDirectory, filename)\n\t\t\tif err := hasAllowedSeedFileExtensions(absFilename); err != nil {\n\t\t\t\treturn errors.E(op, err)\n\t\t\t}\n\n\t\t\tb, err := afero.ReadFile(fs, absFilename)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.E(op, fmt.Errorf(\"error opening file: %w\", err))\n\t\t\t}\n\n\t\t\tsqlAsBytes = append(sqlAsBytes, b)\n\t\t}\n\t} else {\n\t\terr := afero.Walk(fs, seedsDirectory, func(path string, file os.FileInfo, err error) error {\n\t\t\tif file == nil || err != nil {\n\t\t\t\treturn errors.E(op, err)\n\t\t\t}\n\n\t\t\tif err := hasAllowedSeedFileExtensions(file.Name()); err == nil && !file.IsDir() {\n\t\t\t\tb, err := afero.ReadFile(fs, path)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn errors.E(op, fmt.Errorf(\"error opening file: %w\", err))\n\t\t\t\t}\n\n\t\t\t\tsqlAsBytes = append(sqlAsBytes, b)\n\t\t\t}","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/seed/apply.go#L52-L88","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nhasura seed apply --file seeds/01_init.sql   # typo'd name\n# error opening file: open seeds/01_init.sql: no such file or directory\n\n# after\nls seeds/            # confirm actual name\nhasura seed apply --file seeds/01-init.sql","handlingStrategy":"validation","validationCode":"for _, f := range files {\n    abs, _ := filepath.Abs(f)\n    if fi, err := os.Stat(abs); err != nil || fi.IsDir() {\n        return fmt.Errorf(\"seed file %s missing or not a regular file\", f)\n    }\n}\n// then call ApplySeedsToDatabase","typeGuard":null,"tryCatchPattern":"if err := seed.ApplyOnSource(...); err != nil {\n    var pathErr *os.PathError\n    if errors.As(err, &pathErr) && errors.Is(pathErr, fs.ErrNotExist) {\n        // missing file: correct the list and retry\n    }\n}","preventionTips":["Pass absolute seed file paths or run from the project root.","Script a pre-check that every --file argument exists before invoking the CLI."],"tags":["go","seeds","file-read","hasura-cli","filesystem"],"backgroundTag":"file-read-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}