{"record":{"id":"54fe7b3abbf6e8de","repo":"vitessio/vitess","slug":"cannot-read-file-v-v","errorCode":null,"errorMessage":"cannot read file %v: %v","messagePattern":"cannot read file (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/vtctl.go","lineNumber":824,"sourceCode":"\treturn fmt.Sprintf(\"%v %v %v %v %v %v %v %v\", topoproto.TabletAliasString(ti.Alias), keyspace, shard, topoproto.TabletTypeLString(ti.Type), ti.Addr(), ti.MysqlAddr(), fmtMapAwkable(ti.Tags), mtst)\n}\n\n// getFileParam returns a string containing either flag is not \"\",\n// or the content of the file named flagFile\nfunc getFileParam(flag, flagFile, name string) (string, error) {\n\tif flag != \"\" {\n\t\tif flagFile != \"\" {\n\t\t\treturn \"\", fmt.Errorf(\"action requires only one of %v or %v-file\", name, name)\n\t\t}\n\t\treturn flag, nil\n\t}\n\n\tif flagFile == \"\" {\n\t\treturn \"\", fmt.Errorf(\"action requires one of %v or %v-file\", name, name)\n\t}\n\tdata, err := os.ReadFile(flagFile)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"cannot read file %v: %v\", flagFile, err)\n\t}\n\treturn string(data), nil\n}\n\n// keyspaceParamsToKeyspaces builds a list of keyspaces.\n// It supports topology-based wildcards, and plain wildcards.\n// For instance:\n// us*                             // using plain matching\n// *                               // using plain matching\nfunc keyspaceParamsToKeyspaces(ctx context.Context, wr *wrangler.Wrangler, params []string) ([]string, error) {\n\tresult := make([]string, 0, len(params))\n\tfor _, param := range params {\n\t\tif len(param) == 0 {\n\t\t\treturn nil, errors.New(\"empty keyspace param in list\")\n\t\t}\n\t\tif param[0] == '/' {\n\t\t\t// this is a topology-specific path\n\t\t\tresult = append(result, params...)","sourceCodeStart":806,"sourceCodeEnd":842,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/vtctl.go#L806-L842","documentation":"When the -file flag form is used, getFileParam reads the file with os.ReadFile; if that read fails (missing file, permissions, directory instead of file), the underlying OS error is wrapped with the file path and returned.","triggerScenarios":"Running ApplySchema with `--sql-file <path>` (or analogous -file flag) where the path does not exist, is unreadable by the vtctl process user, or points to a directory.","commonSituations":"Relative path resolved from a different working directory in scripts/CI; file created by another user with restrictive permissions; typo in the filename; container image missing the mounted schema file.","solutions":["Verify the file exists at the exact path: check with `ls -l <path>` from the same working directory used for the command.","Fix permissions so the vtctl process user can read the file.","Use an absolute path in scripts and CI to avoid working-directory mismatches.","Confirm volume mounts/configmaps actually contain the file when running in containers."],"exampleFix":"// before\nApplySchema --sql-file ./schem.sql commerce   // typo, file missing\n// after\nApplySchema --sql-file /etc/vitess/schema.sql commerce","handlingStrategy":"validation","validationCode":"const fs = require(\"fs\")\nfs.accessSync(sqlFilePath, fs.constants.R_OK) // throws early if missing/unreadable","typeGuard":"function fileReadable(p) {\n  try { require(\"fs\").accessSync(p, require(\"fs\").constants.R_OK); return true } catch { return false }\n}","tryCatchPattern":"try {\n  run(`vtctlclient ApplySchema --sql-file ${p} commerce`)\n} catch (e) {\n  if (String(e).includes(\"cannot read file\")) {\n    console.error(`File unreadable: ${p}. Check existence, permissions, and cwd.`)\n  } else throw e\n}","preventionTips":["Use absolute paths for -file flags in scripts and CI.","Check file existence and readability from the same user/container that runs vtctl.","Verify volume mounts and configmaps include the schema file before deployment."],"tags":["cli","file-io","apply-schema","oserror"],"backgroundTag":"file-not-found","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}