vitessio/vitess · error

action requires one of %v or %v-file

Error message

action requires one of %v or %v-file

What it means

getFileParam requires at least one source for the named parameter: either the inline flag or the -file flag. If the inline flag is empty AND the -file flag is empty, it returns this error indicating neither was provided.

Source

Thrown at go/vt/vtctl/vtctl.go:820

	// special case for old primary that hasn't updated topo yet
	if ti.PrimaryTermStartTime != nil && ti.PrimaryTermStartTime.Seconds > 0 {
		mtst = protoutil.TimeFromProto(ti.PrimaryTermStartTime).UTC().Format(time.RFC3339)
	}
	return 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)
}

// getFileParam returns a string containing either flag is not "",
// or the content of the file named flagFile
func getFileParam(flag, flagFile, name string) (string, error) {
	if flag != "" {
		if flagFile != "" {
			return "", fmt.Errorf("action requires only one of %v or %v-file", name, name)
		}
		return flag, nil
	}

	if flagFile == "" {
		return "", fmt.Errorf("action requires one of %v or %v-file", name, name)
	}
	data, err := os.ReadFile(flagFile)
	if err != nil {
		return "", fmt.Errorf("cannot read file %v: %v", flagFile, err)
	}
	return string(data), nil
}

// keyspaceParamsToKeyspaces builds a list of keyspaces.
// It supports topology-based wildcards, and plain wildcards.
// For instance:
// us*                             // using plain matching
// *                               // using plain matching
func keyspaceParamsToKeyspaces(ctx context.Context, wr *wrangler.Wrangler, params []string) ([]string, error) {
	result := make([]string, 0, len(params))
	for _, param := range params {
		if len(param) == 0 {
			return nil, errors.New("empty keyspace param in list")

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Provide the value inline (e.g. `--sql "..."`) or via file (e.g. `--sql-file schema.sql`).
  2. Check that the script variable holding the SQL is non-empty before invoking.
  3. Verify flag spelling matches what the command registers (e.g. `--sql-file`, not `--sqlfile`).

Example fix

// before
ApplySchema commerce   // no --sql / --sql-file
// after
ApplySchema --sql-file schema.sql commerce
Defensive patterns

Strategy: validation

Validate before calling

if (!sqlFlag && !sqlFileFlag) {
  throw new Error("ApplySchema requires --sql or --sql-file")
}

Type guard

null

Try / catch

try {
  run("vtctlclient ApplySchema commerce")
} catch (e) {
  if (String(e).includes("requires one of")) {
    console.error("Supply --sql '<statements>' or --sql-file <path>")
  } else throw e
}

Prevention

When it happens

Trigger: Running ApplySchema (or any command using getFileParam) without providing e.g. `--sql` or `--sql-file` — the value parameter is entirely missing from the command line.

Common situations: Forgetting the SQL argument when running ApplySchema interactively; a script variable that is empty causing the flag to be dropped; wrong flag name typo so the intended flag isn't recognized as either parameter.

Understand the failure class

Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/9bfde4a9648e310d. Report an issue: GitHub.