go-kratos/kratos · critical
invalid Discovery config nodes:%+v region:%s zone:%s deployE
Error message
invalid Discovery config nodes:%+v region:%s zone:%s deployEnv:%s host:%s
What it means
fixConfig validates the Discovery client Config at construction: Nodes, Region, Zone, and Env must be non-empty, and Host defaults to os.Hostname(); any gap aborts with this error listing the offending values. It prevents starting a client that could never resolve or register correctly.
Source
Thrown at contrib/registry/discovery/discovery_helper.go:54
_statusUP = "1"
_discoveryAppID = "infra.discovery"
)
// Config Discovery configures.
type Config struct {
Nodes []string
Region string
Zone string
Env string
Host string
}
func fixConfig(c *Config) error {
if c.Host == "" {
c.Host, _ = os.Hostname()
}
if len(c.Nodes) == 0 || c.Region == "" || c.Zone == "" || c.Env == "" || c.Host == "" {
return fmt.Errorf(
"invalid Discovery config nodes:%+v region:%s zone:%s deployEnv:%s host:%s",
c.Nodes,
c.Region,
c.Zone,
c.Env,
c.Host,
)
}
return nil
}
// discoveryInstance represents a server the client connects to.
type discoveryInstance struct {
Region string `json:"region"` // Region is region.
Zone string `json:"zone"` // Zone is IDC.
Env string `json:"env"` // Env prod/pre/uat/fat1
AppID string `json:"appid"` // AppID is mapping service-tree appId.
Hostname string `json:"hostname"` // Hostname is hostname from dockerView on GitHub (pinned to 668db92c2c)
Solutions
- Set every required field: Nodes plus Region, Zone, Env (and Host if the hostname cannot be resolved)
- Wire the discovery config section from env vars so containers always populate it
- Validate the config at startup and fail fast with a clear message
Example fix
// before
r := discovery.New(&discovery.Config{Nodes: []string{"127.0.0.1:7171"}})
// after
r := discovery.New(&discovery.Config{
Nodes: []string{"127.0.0.1:7171"},
Region: "sh",
Zone: "sh001",
Env: "dev",
}) Defensive patterns
Strategy: validation
Validate before calling
func validateDiscoveryConfig(c *discovery.Config) error {
if c.Host == "" {
c.Host, _ = os.Hostname()
}
if len(c.Nodes) == 0 || c.Region == "" || c.Zone == "" || c.Env == "" || c.Host == "" {
return errors.New("discovery config needs Nodes, Region, Zone, Env, Host")
}
return nil
} Prevention
- Fail fast in main on config validation before constructing the registry
- Feed the discovery section from env vars in containers
- Integration-test startup with the full config in CI
When it happens
Trigger: Constructing the discovery registry with a Config missing Nodes, Region, Zone, or Env — or with Host empty and os.Hostname() failing — so fixConfig's validation fails.
Common situations: Migrating configs that only set Nodes; missing REGION/ZONE/DEPLOY_ENV env vars in containers; scratch/distroless images where hostname lookup fails.
Related errors
- Discovery.GetService(%s) not found
- register failed: instance duplicated:
- config: merge src must be map[string]interface{}, got %T
- ErrorCode: %d
- unable to parse repo url
AI-assisted analysis of go-kratos/kratos@668db92c2c (2026-08-16).
Data as JSON: /api/errors/dc07d6ed898d1a1c.
Report an issue: GitHub.