{"record":{"id":"c3dd5200ac23aa9d","repo":"larksuite/cli","slug":"input-relations-d-presence-q-is-invalid","errorCode":null,"errorMessage":"Input.Relations[%d].Presence %q is invalid","messagePattern":"Input\\.Relations\\[(.+?)\\]\\.Presence %q is invalid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_contract.go","lineNumber":30,"sourceCode":"\nfunc compileRelations(definitions []typedRelation, fieldByName map[string]int) ([]compiledRelation, error) {\n\tresult := make([]compiledRelation, 0, len(definitions))\n\tseen := make(map[string]struct{})\n\tfor i, definition := range definitions {\n\t\tminimum := 2\n\t\texact := 0\n\t\tswitch definition.Kind {\n\t\tcase typedRelationExactlyOne, typedRelationAtLeastOne, typedRelationCoOccur, typedRelationConflicts:\n\t\tcase typedRelationRequires:\n\t\t\texact = 2\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"Input.Relations[%d].Kind %q is invalid\", i, definition.Kind)\n\t\t}\n\t\tif exact > 0 && len(definition.Params) != exact || exact == 0 && len(definition.Params) < minimum {\n\t\t\treturn nil, fmt.Errorf(\"Input.Relations[%d] kind %s has invalid param count %d\", i, definition.Kind, len(definition.Params))\n\t\t}\n\t\tif definition.Presence != typedPresenceExplicit && definition.Presence != typedPresenceNonZero {\n\t\t\treturn nil, fmt.Errorf(\"Input.Relations[%d].Presence %q is invalid\", i, definition.Presence)\n\t\t}\n\t\tif definition.Stage != typedStageSourcePreRun && definition.Stage != typedStageAfterPrepare {\n\t\t\treturn nil, fmt.Errorf(\"Input.Relations[%d].Stage %q is invalid\", i, definition.Stage)\n\t\t}\n\t\tcompiled := compiledRelation{kind: definition.Kind, presence: definition.Presence, stage: definition.Stage}\n\t\tlocal := make(map[string]struct{})\n\t\tfor _, name := range definition.Params {\n\t\t\tfield, ok := fieldByName[name]\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"Input.Relations[%d] references unknown param --%s\", i, name)\n\t\t\t}\n\t\t\tif _, duplicate := local[name]; duplicate {\n\t\t\t\treturn nil, fmt.Errorf(\"Input.Relations[%d] repeats param --%s\", i, name)\n\t\t\t}\n\t\t\tlocal[name] = struct{}{}\n\t\t\tcompiled.fields = append(compiled.fields, field)\n\t\t}\n\t\tkeyBytes, _ := json.Marshal(definition)","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_contract.go#L12-L48","documentation":"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.","triggerScenarios":"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.","commonSituations":"Zero-value structs where Presence was forgotten (empty string); copying definitions from older code with different presence vocabulary.","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"],"exampleFix":"// before\n{Kind: typedRelationConflicts, Params: []string{\"a\",\"b\"}, Presence: \"\"}\n// after\n{Kind: typedRelationConflicts, Params: []string{\"a\",\"b\"}, Presence: typedPresenceExplicit}","handlingStrategy":"validation","validationCode":"func knownPresence(p typedPresence) bool {\n\treturn p == typedPresenceExplicit || p == typedPresenceNonZero\n}","typeGuard":"func isTypedPresence(v any) bool {\n\tp, ok := v.(typedPresence)\n\treturn ok && knownPresence(p)\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["go","validation","compile-time","relations"],"backgroundTag":"invalid-enum-value","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}