larksuite/cli · error
--%s must be an integer, got %s
Error message
--%s must be an integer, got %s
What it means
Raw-type validation error from validateRawTypes: a flag targeting Go `int` received a valid JSON number with a fractional part (e.g. 1.9). Int() would silently truncate it, so the validator rejects non-integers to keep batch and standalone cobra behavior identical. The intermediate error is wrapped into a typed operations validation error by the batch dispatcher.
Source
Thrown at shortcuts/sheets/flag_view.go:307
if !ok {
// flag-defs use hyphen names; tolerate the underscore form users send.
name = strings.ReplaceAll(rawKey, "_", "-")
typ, ok = declaredType[name]
}
if !ok {
continue // unknown key — leave it for the translator / schema layer
}
switch typ {
case "int":
// Int(): float64 → int(t) truncates, so a non-integer number would
// be silently floored (1.9 → 1). Standalone cobra rejects it at
// parse time; reject here too to keep batch/standalone parity.
f, isNum := val.(float64)
if !isNum {
return fmt.Errorf("--%s must be a number, got %s", name, jsonTypeName(val)) //nolint:forbidigo // intermediate error; the batch dispatcher wraps it into a typed operations validation error
}
if math.Trunc(f) != f {
return fmt.Errorf("--%s must be an integer, got %s", name, strconv.FormatFloat(f, 'g', -1, 64)) //nolint:forbidigo // intermediate error; the batch dispatcher wraps it into a typed operations validation error
}
case "float64":
if _, isNum := val.(float64); !isNum {
return fmt.Errorf("--%s must be a number, got %s", name, jsonTypeName(val)) //nolint:forbidigo // intermediate error; the batch dispatcher wraps it into a typed operations validation error
}
case "bool":
if _, isBool := val.(bool); !isBool {
return fmt.Errorf("--%s must be a boolean, got %s", name, jsonTypeName(val)) //nolint:forbidigo // intermediate error; the batch dispatcher wraps it into a typed operations validation error
}
}
}
return nil
}
// normalizeAndValidateEnums applies the same flat string-enum contract as the
// standalone cobra path. Canonical casing and known aliases are rewritten in
// place; unknown values are rejected before a translator can silently fall
// back to a different operation.View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Round or truncate the value explicitly upstream and pass an integer literal.
- Verify the field type via --print-schema; if a float is actually needed, use the float-typed field.
- Fix the upstream computation producing the fractional number.
Example fix
// before --row_id 2.5 // non-integer // after --row_id 2
Defensive patterns
Strategy: validation
Validate before calling
function assertInteger(v) {
if (typeof v !== "number" || !Number.isInteger(v)) {
throw new Error(`expected integer, got ${v}`);
}
} Type guard
function isJsonInteger(v: unknown): v is number {
return typeof v === "number" && Number.isFinite(v) && Number.isInteger(v);
} Try / catch
try {
runCommand(args);
} catch (e) {
if (/must be an integer/.test(e.message)) {
// round or Math.trunc the value and retry
}
} Prevention
- Round explicitly upstream rather than relying on truncation.
- Use integer math when computing indices and counts.
- Confirm field types via --print-schema; use float fields for fractional values.
When it happens
Trigger: Passing `--flag 1.9` or any non-integral float for an int-typed field, e.g. a row index of 2.5 from computed or averaged upstream values.
Common situations: Deriving indices from division or averages; passing floats because a related field was float64; unit mismatches producing fractional values.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- --%s must be a number, got %s
- +csv-get truncated the requested range at {source_range}; na
- Multiple sheets matched; pass --sheet-id or --sheet-name
- %svalue %v is below minimum %v
- %svalue %v is above maximum %v
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/b91e320c74e9884c.
Report an issue: GitHub.