larksuite/cli · error

got both and , which are two names for the same flag, with…

Error message

%s got both %q and %q, which are two names for the same flag, with different values — keep %q

What it means

When the input key is an alias for a vocab-known logical key and that logical key is already claimed by a different spelling with a different value, the dispatcher reports two names for the same flag carrying conflicting values and names the surviving spelling to keep.

Solutions

  1. Keep only the spelling named in the error (the `keep` value) and delete the other.
  2. Make both spellings carry the same value if repetition is accidental duplication from templating.
  3. Audit your op-building code for paths that can add the same logical flag twice.

Example fix

// before
{"field_key": "fldA", "fieldKey": "fldB"}
// after
{"field_key": "fldB"}
Defensive patterns

Strategy: validation

Validate before calling

func assertSingleFlag(op map[string]interface{}, logical string, spellings ...string) error {
    present := []string{}
    for _, s := range spellings {
        if _, ok := op[s]; ok { present = append(present, s) }
    }
    if len(present) > 1 {
        return fmt.Errorf("flag %s set via %v; keep one", logical, present)
    }
    return nil
}

Prevention

When it happens

Trigger: A sub-op sets the same logical flag via two different spellings (e.g. `fieldKey` and `field_key`) with different values; the second spelling's turn hits the canonical claim recorded by the first.

Common situations: Scripted payloads that build the op conditionally and append the same field twice in different cases; template substitutions injecting a second copy of a flag under another casing.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/7080443d49c0b7b4. Report an issue: GitHub.

Appendix: source

Thrown at shortcuts/sheets/batch_op_dispatch.go:490

			// The alias AND its target are both present. This key is recognized,
			// so it must not fall through to the generic "unknown input key"
			// below — the claim() conflict message never fires here either,
			// because keys are walked in sorted order and the alias can sort
			// before its target ("size" < "width"), so nothing has claimed the
			// logical key yet. Name both spellings and the survivor.
			taken := target
			if underscoreTaken {
				taken = underscored
			}
			if jsonEqual(input[k], input[taken]) {
				delete(input, k) // same value under two names: drop the alias.
				// Hand the logical key over to the surviving spelling, or the
				// claim recorded above would still point at the deleted alias
				// and make that spelling's own turn read as a conflict.
				canonical[target] = taken
				continue
			}
			return fmt.Errorf("%s got both %q and %q, which are two names for the same flag, with different values — keep %q", sc, k, taken, taken) //nolint:forbidigo // intermediate error; the batch dispatcher wraps it into a typed operations validation error
		}
		if strings.ToLower(hv) == "ranges" && vocab["range"] && !vocab["ranges"] {
			if _, taken := input["range"]; taken {
				return fmt.Errorf("%s got both %q and \"range\" — keep \"range\" and drop %q", sc, k, k) //nolint:forbidigo // intermediate error; the batch dispatcher wraps it into a typed operations validation error
			}
			if arr, isArr := input[k].([]interface{}); isArr {
				if len(arr) == 1 {
					if s, isStr := arr[0].(string); isStr {
						input["range"] = s
						delete(input, k)
						continue
					}
				}
				return fmt.Errorf("%s takes a single \"range\" per sub-op, got %d entries in %q — split them into %d sub-ops (one per range)", sc, len(arr), k, len(arr)) //nolint:forbidigo // intermediate error; the batch dispatcher wraps it into a typed operations validation error
			}
			if s, isStr := input[k].(string); isStr {
				input["range"] = s
				delete(input, k)

View on GitHub (pinned to 7fd6ef3c07)