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 nil

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Fix the CurrentConfigGetter implementation so it returns a fully populated common.Config whose ChannelGroup contains the Orderer/Application groups and Values.
  2. 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.
  3. Call config.ValidateConfig(cfg) defensively before serving discovery queries and fall back to re-fetching the latest config block when validation fails.
  4. 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

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


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/f63379d37477de56. Report an issue: GitHub.