hyperledger/fabric · error
field Config.ChannelGroup is nil
Error message
field Config.ChannelGroup is nil
What it means
ValidateConfig sanity-checks a common.Config retrieved by CurrentConfigGetter.GetCurrConfig before DiscoverySupport.Config uses it. This error means the Config struct has a nil ChannelGroup, i.e. the top-level channel configuration group is absent, so no channel structure exists to walk. The caller (Config) wraps it with 'config is invalid'.
Source
Thrown at discovery/support/config/support.go:230
continue
}
fabricConfig := &msp.FabricMSPConfig{}
if err := proto.Unmarshal(mspConfig.Config, fabricConfig); err != nil {
return errors.Wrap(err, "failed marshaling FabricMSPConfig")
}
if _, exists := output[fabricConfig.Name]; exists {
continue
}
output[fabricConfig.Name] = fabricConfig
}
}
return nil
}
func ValidateConfig(c *common.Config) error {
if c.ChannelGroup == nil {
return errors.New("field Config.ChannelGroup is nil")
}
grps := c.ChannelGroup.Groups
if grps == nil {
return errors.New("field Config.ChannelGroup.Groups is nil")
}
for _, field := range []string{channelconfig.OrdererGroupKey, channelconfig.ApplicationGroupKey} {
grp, exists := grps[field]
if !exists {
return fmt.Errorf("key Config.ChannelGroup.Groups[%s] is missing", field)
}
if grp.Groups == nil {
return fmt.Errorf("key Config.ChannelGroup.Groups[%s].Groups is nil", field)
}
}
if c.ChannelGroup.Values == nil {
return errors.New("field Config.ChannelGroup.Values is nil")
}
return nilView on GitHub (pinned to 2736b63f8f)
Solutions
- Fix the CurrentConfigGetter implementation so it returns a fully populated common.Config whose ChannelGroup contains the Orderer/Application groups and Values.
- If the config comes from a block, unmarshal the envelope's payload data into common.Config (not common.Block or another type) and verify err == nil.
- Call config.ValidateConfig(cfg) defensively before serving discovery queries and fall back to re-fetching the latest config block when validation fails.
- In tests, build fixtures with all required fields: ChannelGroup.Groups{"Orderer": ..., "Application": ...} and non-nil Values.
Example fix
// before
cfg := &common.Config{} // ChannelGroup nil
// after
cfg := &common.Config{
ChannelGroup: &common.ConfigGroup{
Groups: map[string]*common.ConfigGroup{
channelconfig.OrdererGroupKey: {Groups: map[string]*common.ConfigGroup{}},
channelconfig.ApplicationGroupKey: {Groups: map[string]*common.ConfigGroup{}},
},
Values: map[string]*common.ConfigValue{},
},
} Defensive patterns
Strategy: validation
Validate before calling
cfg := getter.GetCurrConfig(channel)
if cfg == nil || cfg.ChannelGroup == nil {
return fmt.Errorf("channel %s config is missing ChannelGroup; re-fetch latest config block", channel)
}
if err := config.ValidateConfig(cfg); err != nil {
return fmt.Errorf("config is invalid: %w", err)
} Type guard
func hasChannelGroup(c *common.Config) bool {
return c != nil && c.ChannelGroup != nil
} Try / catch
res, err := support.Config(channel)
if err != nil && strings.Contains(err.Error(), "field Config.ChannelGroup is nil") {
// rebuild/refresh the config cache entry from the newest config block before retrying
err = refreshAndRetry(channel)
} Prevention
- Never return a zero-value &common.Config{} from custom CurrentConfigGetter implementations; return nil so callers distinguish 'no config' from 'bad config'.
- Run discovery config.ValidateConfig on every config before caching it.
- Unmarshal config envelopes' payload data strictly into common.Config and check errors.
- In tests, construct fixtures with a fully populated ChannelGroup.
When it happens
Trigger: GetCurrConfig(channel) returns a non-nil *common.Config that was constructed without a ChannelGroup: (1) a config block unmarshaled into the wrong message type; (2) a hand-built or default (zero-value) common.Config stored in the config cache; (3) an empty/partially unmarshaled protobuf where the ChannelGroup field was never populated.
Common situations: Custom CurrentConfigGetterFunc implementations returning &common.Config{} placeholders in tests or mocks; config caches populated from an empty/malformed envelope; migration tooling that wrote an empty Config struct; unit tests exercising discovery support with incomplete fixtures.
Related errors
- field Config.ChannelGroup.Groups is nil
- key Config.ChannelGroup.Groups[%s] is missing
- Setup error: unsupported msp type %d
- id cannot be nil if buf is not nil
- depspec cannot be nil if buf is not nil
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/f63379d37477de56.
Report an issue: GitHub.