hasura/graphql-engine · error
expected extension to be one of %v but got %s on file %s
Error message
expected extension to be one of %v but got %s on file %s
What it means
The seed-apply command only reads files with whitelisted extensions (the allowedExtensions list, e.g. .sql) from the seeds directory. hasAllowedSeedFileExtensions inspects each candidate file and rejects anything whose extension is not in that list, so non-SQL junk never reaches the database.
Source
Thrown at cli/seed/apply.go:27
"github.com/hasura/graphql-engine/cli/v2"
"github.com/hasura/graphql-engine/cli/v2/internal/errors"
"github.com/hasura/graphql-engine/cli/v2/internal/hasura"
"github.com/spf13/afero"
)
func hasAllowedSeedFileExtensions(filename string) error {
var op errors.Op = "seed.hasAllowedSeedFileExtensions"
extension := filepath.Ext(filename)
allowedExtensions := []string{".sql", ".SQL"}
if slices.Contains(allowedExtensions, extension) {
return nil
}
return errors.E(
op,
fmt.Errorf(
"expected extension to be one of %v but got %s on file %s",
allowedExtensions,
extension,
filename,
),
)
}
// ApplySeedsToDatabase will read all .sql files in the given
// directory and apply it to hasura.
func (d *Driver) ApplySeedsToDatabase(
fs afero.Fs,
rootSeedsDirectory string,
filenames []string,
source cli.Source,
) error {
var op errors.Op = "seed.Driver.ApplySeedsToDatabase"
View on GitHub (pinned to 724551b9ae)
Solutions
- Rename the file to use an allowed extension (.sql) if it is a real seed.
- Move non-seed files (READMEs, backups, notes) out of the seeds directory.
- Delete stray files like .DS_Store or editor temp files from seeds/.
- Do not widen allowedExtensions unless you fully control the directory contents.
Example fix
# before seeds/ 0-seed.sql notes.txt # rejected: expected extension to be one of [.sql] # after seeds/ 0-seed.sql # notes.txt moved to project root or docs/
Defensive patterns
Strategy: validation
Validate before calling
var allowed = map[string]bool{".sql": true}
filepath.WalkDir(seedsDir, func(p string, d fs.DirEntry, err error) error {
if !d.IsDir() && !allowed[strings.ToLower(filepath.Ext(p))] {
return nil // skip, don't let the CLI reject it
}
return nil
}) Type guard
func isAllowedSeedFile(name string, allowed []string) bool {
return slices.Contains(allowed, strings.ToLower(filepath.Ext(name)))
} Try / catch
if err := ApplySeedsToDatabase(...); err != nil && strings.Contains(err.Error(), "expected extension to be one of") {
// clean the seeds dir and re-run
} Prevention
- Keep only .sql files in the seeds directory.
- Store notes/backups outside seeds/ or with non-matching extensions the walker still skips (they cause errors — so just move them out).
- Add a CI lint step: find seeds -type f ! -name '*.sql' fails the build.
When it happens
Trigger: A file in the seeds directory ends with an extension not in allowedExtensions: .txt, .sql.bak, .md, or no extension at all. Triggered by ApplySeedsToDatabase when iterating (explicit-file mode) or walking (directory mode) the seeds folder.
Common situations: Leaving README.md, backup files like 0-seed.sql.bak, editor swap files, or .DS_Store inside the seeds/ directory; or renaming seed files from .sql to something else and forgetting the whitelist only accepts .sql.
Related errors
- getting list of seed files to move: %w
- error opening file: %w
- error walking the directory path: %w
- database %s of kind %s is not supported
- no data provided
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/d5b16990270a6944.
Report an issue: GitHub.