larksuite/cli · error
domain name must be non-empty and trimmed
Error message
domain name must be non-empty and trimmed
What it means
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.
Source
Thrown at internal/commandhost/compile.go:107
}
// businessDomains reports the domains a command set may extend. It reads the
// service registry rather than deriving domains from shortcuts.AllShortcuts:
// approval, attendance and mindnotes ship only typed and raw API commands, and
// a shortcut-derived set would reject them as non-existent.
func businessDomains() map[string]struct{} {
names := registry.AllServiceNames()
domains := make(map[string]struct{}, len(names))
for _, name := range names {
domains[name] = struct{}{}
}
return domains
}
func validateDomain(domain command.HostDomain, existing map[string]struct{}) error {
name := strings.TrimSpace(domain.Name)
if name == "" || name != domain.Name {
return fmt.Errorf("domain name must be non-empty and trimmed")
}
if _, ok := existing[name]; !ok {
return fmt.Errorf("ExtendDomain target %q does not exist", name)
}
return nil
}
func compileCommand(definition command.HostDefinition) (common.Shortcut, error) {
hooks := convertHooks(definition)
hooks.NewArgs = definition.NewArgs
return common.CompileCommandDefinition(commandbridge.Definition{
Metadata: definition.Metadata,
Input: definition.Input,
Output: definition.Output,
ArgsType: definition.ArgsType,
DataType: definition.DataType,
Hooks: hooks,
PageOutput: definition.PageOutput,View on GitHub (pinned to 7fd6ef3c07)
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
Example fix
// before
domain := command.HostDomain{Name: " " + svc}
// after
domain := command.HostDomain{Name: strings.TrimSpace(svc)} Defensive patterns
Strategy: validation
Validate before calling
func validDomainName(n string) bool {
t := strings.TrimSpace(n)
return t != "" && t == n
} Try / catch
if err := commandhost.CompileSets(sets); err != nil {
if strings.Contains(err.Error(), "domain name must be non-empty and trimmed") {
return fmt.Errorf("check HostDomain.Name literals: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: CompileSets receives a command.HostDomain whose Name is "", " doc", or "doc ".
Common situations: 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.
Related errors
- Invalid column: {column!r}
- Invalid column index: {index}
- anchor outside sheet: {position!r}
- Missing row_count/column_count for sheet {sheet_title(sheet)
- Missing sheet_id for sheet {title!r}
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/08d0261c6f0e7c1b.
Report an issue: GitHub.