{"record":{"id":"3a390bed610c8579","repo":"hasura/graphql-engine","slug":"cannot-read-file-s-w","errorCode":null,"errorMessage":"cannot read file %s: %w","messagePattern":"cannot read file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/migrate/source/parse.go","lineNumber":125,"sourceCode":"\t\t}\n\n\t\treturn &Migration{\n\t\t\tVersion:    versionUint64,\n\t\t\tIdentifier: m[2],\n\t\t\tDirection:  direction,\n\t\t}, nil\n\t}\n\n\treturn nil, errors.E(op, ErrParse)\n}\n\n// Validate file to check for empty sql or yaml content.\nfunc IsEmptyFile(m *Migration, directory string) (bool, error) {\n\tvar op errors.Op = \"source.IsEmptyFile\"\n\n\tdata, err := os.ReadFile(filepath.Join(directory, m.Raw))\n\tif err != nil {\n\t\treturn false, errors.E(op, fmt.Errorf(\"cannot read file %s: %w\", m.Raw, err))\n\t}\n\n\tswitch direction := m.Direction; direction {\n\tcase MetaUp, MetaDown:\n\t\tvar t []any\n\n\t\terr = yaml.Unmarshal(data, &t)\n\t\tif err != nil {\n\t\t\treturn false, errors.E(op, fmt.Errorf(\"invalid yaml file: %s: %w\", m.Raw, err))\n\t\t}\n\n\t\tif len(t) == 0 {\n\t\t\treturn false, nil\n\t\t}\n\tcase Up, Down:\n\t\tif string(data) == \"\" {\n\t\t\treturn false, nil\n\t\t}","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/migrate/source/parse.go#L107-L143","documentation":"Thrown by IsEmptyFile, which Scan calls for every migration file to skip empty ones: it does os.ReadFile on migrations/<raw-name> and any read failure is wrapped as 'cannot read file <name>'. Typical causes are a missing file, permission errors, or path/permission issues where the CLI runs.","triggerScenarios":"A Migration entry whose m.Raw file doesn't exist on disk (deleted or renamed after the directory listing), running the CLI without read permission on migrations/, or a directory value that doesn't match where files live (symlink/oddx case). Any migrate command that scans the source triggers it.","commonSituations":"Deleting or renaming migration files while another process/CI job runs; checking out a repo on a case-sensitive filesystem after files were renamed with different case; read-only mounts; stale editor state referencing removed files.","solutions":["Verify every file listed in migrations/ actually exists: ls the directory and compare with the error's file name","Restore the missing file from git (git status / git checkout -- migrations/)","Check read permissions for the running user on the migrations directory","Ensure you run migrate commands from the project root so the relative directory resolves"],"exampleFix":"# before\n$ rm migrations/05_old.up.sql && hasura migrate apply\n# cannot read file 05_old.up.sql\n\n# after\n$ git checkout -- migrations/05_old.up.sql && hasura migrate apply","handlingStrategy":"validation","validationCode":"// Verify every migration file is readable before scanning\nfor m := range expectedMigrations {\n    if _, err := os.Stat(filepath.Join(\"migrations\", m)); err != nil {\n        return fmt.Errorf(\"migration file missing: %s\", m)\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := source.IsEmptyFile(m, dir); err != nil {\n    if strings.Contains(err.Error(), \"cannot read file\") {\n        // restore missing/unreadable file from VCS\n    }\n}","preventionTips":["Keep migrations directory fully in git","Avoid editing/deleting migration files during running jobs","Run CLI from the project root"],"tags":["filesystem","migrations","file-not-found","hasura"],"backgroundTag":"file-read-error","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}