{"record":{"id":"08d0261c6f0e7c1b","repo":"larksuite/cli","slug":"domain-name-must-be-non-empty-and-trimmed","errorCode":null,"errorMessage":"domain name must be non-empty and trimmed","messagePattern":"domain name must be non-empty and trimmed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/commandhost/compile.go","lineNumber":107,"sourceCode":"}\n\n// businessDomains reports the domains a command set may extend. It reads the\n// service registry rather than deriving domains from shortcuts.AllShortcuts:\n// approval, attendance and mindnotes ship only typed and raw API commands, and\n// a shortcut-derived set would reject them as non-existent.\nfunc businessDomains() map[string]struct{} {\n\tnames := registry.AllServiceNames()\n\tdomains := make(map[string]struct{}, len(names))\n\tfor _, name := range names {\n\t\tdomains[name] = struct{}{}\n\t}\n\treturn domains\n}\n\nfunc validateDomain(domain command.HostDomain, existing map[string]struct{}) error {\n\tname := strings.TrimSpace(domain.Name)\n\tif name == \"\" || name != domain.Name {\n\t\treturn fmt.Errorf(\"domain name must be non-empty and trimmed\")\n\t}\n\tif _, ok := existing[name]; !ok {\n\t\treturn fmt.Errorf(\"ExtendDomain target %q does not exist\", name)\n\t}\n\treturn nil\n}\n\nfunc compileCommand(definition command.HostDefinition) (common.Shortcut, error) {\n\thooks := convertHooks(definition)\n\thooks.NewArgs = definition.NewArgs\n\treturn common.CompileCommandDefinition(commandbridge.Definition{\n\t\tMetadata:   definition.Metadata,\n\t\tInput:      definition.Input,\n\t\tOutput:     definition.Output,\n\t\tArgsType:   definition.ArgsType,\n\t\tDataType:   definition.DataType,\n\t\tHooks:      hooks,\n\t\tPageOutput: definition.PageOutput,","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/commandhost/compile.go#L89-L125","documentation":"validateDomain enforces that every HostDomain's Name is non-empty and contains no leading/trailing whitespace. Domain names are used as identity keys for ExtendDomain targets, so untrimmed or empty names are rejected at compile time.","triggerScenarios":"CompileSets receives a command.HostDomain whose Name is \"\", \" doc\", or \"doc \".","commonSituations":"Building a domain name from config or a variable that is empty; accidentally adding a space in a string literal; trimming applied on one side of a comparison but not the stored value.","solutions":["Set domain.Name to a non-empty literal with no surrounding whitespace","Run strings.TrimSpace on the value before constructing the HostDomain and assign the trimmed result","Guard extension code that derives domain names from user/config input"],"exampleFix":"// before\ndomain := command.HostDomain{Name: \" \" + svc}\n// after\ndomain := command.HostDomain{Name: strings.TrimSpace(svc)}","handlingStrategy":"validation","validationCode":"func validDomainName(n string) bool {\n    t := strings.TrimSpace(n)\n    return t != \"\" && t == n\n}","typeGuard":null,"tryCatchPattern":"if err := commandhost.CompileSets(sets); err != nil {\n    if strings.Contains(err.Error(), \"domain name must be non-empty and trimmed\") {\n        return fmt.Errorf(\"check HostDomain.Name literals: %w\", err)\n    }\n    return err\n}","preventionTips":["Define domain names as package-level constants","Never build domain names from untrimmed input without strings.TrimSpace","Add a test asserting every registered domain name passes validDomainName"],"tags":["go","validation","domain-name"],"backgroundTag":"invalid-domain-name","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"}