{"record":{"id":"89c6f94c70811ad0","repo":"larksuite/cli","slug":"w-source-q-w-89c6f9","errorCode":null,"errorMessage":"%w: source %q: %w","messagePattern":"%w: source %q: %w","errorType":"validation","errorClass":"ErrInvalidRemap","httpStatus":null,"severity":"error","filePath":"internal/skillref/resolver.go","lineNumber":48,"sourceCode":"\texact   map[string]Ref\n}\n\n// New validates mappings against content and returns an immutable resolver.\n//\n// Explicit targets are build-integrity declarations and must exist. In\n// contrast, an unmapped canonical reference may be absent: presenters then\n// omit the complete guidance fragment that owns it.\nfunc New(content fs.FS, mappings []Mapping) (*Resolver, error) {\n\tr := &Resolver{\n\t\tcontent: content,\n\t\tskills:  make(map[string]Ref),\n\t\texact:   make(map[string]Ref),\n\t}\n\tseen := make(map[string]bool, len(mappings))\n\tfor _, mapping := range mappings {\n\t\tfrom, to := mapping.From, mapping.To\n\t\tif _, err := Parse(from.String()); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"%w: source %q: %w\", ErrInvalidRemap, from.String(), err)\n\t\t}\n\t\tif _, err := Parse(to.String()); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"%w: target %q: %w\", ErrInvalidRemap, to.String(), err)\n\t\t}\n\t\tkey := from.String()\n\t\tif seen[key] {\n\t\t\treturn nil, fmt.Errorf(\"%w: source %q is mapped more than once\", ErrInvalidRemap, key)\n\t\t}\n\t\tseen[key] = true\n\n\t\tif from.Path == \"\" {\n\t\t\tif to.Path != \"\" {\n\t\t\t\treturn nil, fmt.Errorf(\n\t\t\t\t\t\"%w: whole-skill source %q requires a bare target skill, got %q\",\n\t\t\t\t\tErrInvalidRemap, key, to.String())\n\t\t\t}\n\t\t\tr.skills[from.Skill] = to\n\t\t} else {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/skillref/resolver.go#L30-L66","documentation":"skillref.New validates every ReferenceRemap by re-parsing From and To. If either endpoint is malformed, construction fails with ErrInvalidRemap wrapping the endpoint (\"source\" or \"target\"), its string form, and the underlying skillref.Parse error. Remaps are build-integrity declarations, so a bad endpoint aborts resolver construction.","triggerScenarios":"Calling skillref.New (directly or via skillpolicy.ResolveWithReferences) with a Mapping whose From or To Ref serializes to an invalid reference — e.g. zero-value Ref{}, skill name with slash/dot, invalid relative path, or trailing slash.","commonSituations":"Plugin authors hand-build Ref values with empty or wrong fields; a Remap source written as \"skill/path/extra\" that violates name rules; a Ref built from an unvalidated user/config string.","solutions":["Fix the Ref endpoint named in the message (source = From, target = To) so skillref.Parse succeeds; read the wrapped error for the specific rule broken.","Validate endpoints with skillref.Parse / ValidSkillName when constructing the Mapping instead of after.","Ensure whole-skill remaps use bare names on both sides (From.Path == \"\" requires To.Path == \"\").","Check that the remap targets exist in the composed tree too — after fixing syntax, the next New failure may be a dangling target."],"exampleFix":"// before\nMapping{From: Ref{}, To: Ref{Skill: \"auth/references\"}}\n// after\nMapping{From: Ref{Skill: \"old-auth\"}, To: Ref{Skill: \"auth\"}}","handlingStrategy":"validation","validationCode":"for _, m := range mappings {\n    if _, err := skillref.Parse(m.From.String()); err != nil { return fmt.Errorf(\"remap source: %w\", err) }\n    if _, err := skillref.Parse(m.To.String()); err != nil { return fmt.Errorf(\"remap target: %w\", err) }\n}","typeGuard":"func validMapping(m skillref.Mapping) bool {\n    _, e1 := skillref.Parse(m.From.String())\n    _, e2 := skillref.Parse(m.To.String())\n    return e1 == nil && e2 == nil\n}","tryCatchPattern":"r, err := skillref.New(content, mappings)\nif errors.Is(err, skillref.ErrInvalidRemap) {\n    return fmt.Errorf(\"fix ReferenceRemaps in the SkillsOverlay: %w\", err)\n}","preventionTips":["Construct Ref values explicitly (Skill plus optional Path); never pass zero-value Ref{}","Pre-validate every Mapping endpoint with skillref.Parse before building the overlay","Keep whole-skill remaps bare on both sides; verify remap targets exist in the composed tree"],"tags":["go","skillref","remap","input-validation","sentinel-error"],"backgroundTag":"invalid-skill-reference-remap","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"}