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

  1. Set domain.Name to a non-empty literal with no surrounding whitespace
  2. Run strings.TrimSpace on the value before constructing the HostDomain and assign the trimmed result
  3. 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

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


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/08d0261c6f0e7c1b. Report an issue: GitHub.