larksuite/cli · error
Input.Relations[%d].Presence %q is invalid
Error message
Input.Relations[%d].Presence %q is invalid
What it means
compileRelations requires each relation's Presence to be typedPresenceExplicit or typedPresenceNonZero; any other value is rejected at compile time. Presence controls how a param counts as 'present' for the relation check (user-provided vs non-zero value), so an invalid value would make runtime enforcement ambiguous.
Source
Thrown at shortcuts/common/typed_compile_contract.go:30
func compileRelations(definitions []typedRelation, fieldByName map[string]int) ([]compiledRelation, error) {
result := make([]compiledRelation, 0, len(definitions))
seen := make(map[string]struct{})
for i, definition := range definitions {
minimum := 2
exact := 0
switch definition.Kind {
case typedRelationExactlyOne, typedRelationAtLeastOne, typedRelationCoOccur, typedRelationConflicts:
case typedRelationRequires:
exact = 2
default:
return nil, fmt.Errorf("Input.Relations[%d].Kind %q is invalid", i, definition.Kind)
}
if exact > 0 && len(definition.Params) != exact || exact == 0 && len(definition.Params) < minimum {
return nil, fmt.Errorf("Input.Relations[%d] kind %s has invalid param count %d", i, definition.Kind, len(definition.Params))
}
if definition.Presence != typedPresenceExplicit && definition.Presence != typedPresenceNonZero {
return nil, fmt.Errorf("Input.Relations[%d].Presence %q is invalid", i, definition.Presence)
}
if definition.Stage != typedStageSourcePreRun && definition.Stage != typedStageAfterPrepare {
return nil, fmt.Errorf("Input.Relations[%d].Stage %q is invalid", i, definition.Stage)
}
compiled := compiledRelation{kind: definition.Kind, presence: definition.Presence, stage: definition.Stage}
local := make(map[string]struct{})
for _, name := range definition.Params {
field, ok := fieldByName[name]
if !ok {
return nil, fmt.Errorf("Input.Relations[%d] references unknown param --%s", i, name)
}
if _, duplicate := local[name]; duplicate {
return nil, fmt.Errorf("Input.Relations[%d] repeats param --%s", i, name)
}
local[name] = struct{}{}
compiled.fields = append(compiled.fields, field)
}
keyBytes, _ := json.Marshal(definition)View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Set Presence to typedPresenceExplicit or typedPresenceNonZero
- If you relied on the zero value, explicitly pick the intended constant (usually typedPresenceExplicit)
- Search definitions for `Presence:` fields and validate each against the two constants
Example fix
// before
{Kind: typedRelationConflicts, Params: []string{"a","b"}, Presence: ""}
// after
{Kind: typedRelationConflicts, Params: []string{"a","b"}, Presence: typedPresenceExplicit} Defensive patterns
Strategy: validation
Validate before calling
func knownPresence(p typedPresence) bool {
return p == typedPresenceExplicit || p == typedPresenceNonZero
} Type guard
func isTypedPresence(v any) bool {
p, ok := v.(typedPresence)
return ok && knownPresence(p)
} Prevention
- Never rely on the struct zero value for Presence; set the constant explicitly
- Use typedPresenceExplicit by default; choose NonZero only when zero-values should count as absent
- Add a compile test asserting Presence on every declared relation
When it happens
Trigger: Setting Presence to an empty string or a made-up value like "provided" instead of one of the two supported constants in a typedRelation declaration.
Common situations: Zero-value structs where Presence was forgotten (empty string); copying definitions from older code with different presence vocabulary.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Input.Relations[%d].Kind %q is invalid
- Input.Relations[%d] kind %s has invalid param count %d
- Input.Relations[%d].Stage %q is invalid
- Input.Relations[%d] references unknown param --%s
- Invalid column: {column!r}
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/c3dd5200ac23aa9d.
Report an issue: GitHub.