openimsdk/open-im-server · error

config field %s %s not found

Error message

config field %s %s not found

What it means

parseConf uses reflection to populate struct fields from the service's own config (x.config / x.confPath). When the field's declared type does not match any of the supported config kinds (string path, AllConfig, *AllConfig), the reflection switch falls into the default branch and returns this error naming the offending types. It means the configuration struct contains a field the config loader does not know how to inject.

Source

Thrown at cmd/main.go:224

		typeField := tof.Field(i)
		if !typeField.IsExported() {
			continue
		}
		field := vof.Field(i)
		pkt := x.getTypePath(field.Type())
		val, ok := x.conf[pkt]
		if !ok {
			switch field.Interface().(type) {
			case config.Index:
				field.Set(reflect.ValueOf(config.Index(x.index)))
			case config.Path:
				field.SetString(x.confPath)
			case config.AllConfig:
				field.Set(reflect.ValueOf(x.config))
			case *config.AllConfig:
				field.Set(reflect.ValueOf(&x.config))
			default:
				return fmt.Errorf("config field %s %s not found", vof.Type().Name(), typeField.Name)
			}
			continue
		}
		field.Set(val)
	}
	return nil
}

func (x *cmds) add(name string, block bool, fn func(ctx context.Context) error) {
	x.cmds = append(x.cmds, cmdName{Name: name, Block: block, Func: fn})
}

func (x *cmds) initLog() error {
	conf := x.config.Log
	if err := log.InitLoggerFromConfig(
		"openim-service-log",
		program.GetProcessName(),
		"", "",

View on GitHub (pinned to 175a7bb067)

Solutions

  1. Change the offending struct field's type to config.AllConfig, *config.AllConfig, or string (config path) so the reflection switch can handle it
  2. Add a case to the type switch in parseConf that supports the new field type
  3. Remove or move the unsupported field out of the struct that parseConf fills via reflection

Example fix

// before
MyExtra string // unsupported type in parseConf switch -> error
// after
import "github.com/openimsdk/tools/db/config"
AllConfig config.AllConfig // supported by parseConf's type switch
Defensive patterns

Strategy: validation

Validate before calling

func validateConfFields(cfg interface{}) error {
	t := reflect.TypeOf(cfg).Elem()
	for i := 0; i < t.NumField(); i++ {
		switch t.Field(i).Type.Name() {
		case "string", "AllConfig":
		default:
			if t.Field(i).Type != reflect.TypeOf(&config.AllConfig{}) {
				return fmt.Errorf("unsupported config field type: %s %s", t.Field(i).Type, t.Field(i).Name)
			}
		}
	}
	return nil
}

Type guard

func isSupportedConfigType(t reflect.Type) bool {
	return t.Kind() == reflect.String || t == reflect.TypeOf(config.AllConfig{}) || t == reflect.TypeOf(&config.AllConfig{})
}

Prevention

When it happens

Trigger: A service config struct declares a field whose type is not config.AllConfig, *config.AllConfig, or a string for the conf path, so typeField.Type hits the default case in the reflect switch during parseConf at startup.

Common situations: Adding a custom field to a service config struct; renaming or changing the type of an existing config field after a version upgrade; copying a config struct from another service that had extra fields the loader can't handle.

Related errors


AI-assisted analysis of openimsdk/open-im-server@175a7bb067 (2026-09-04). Data as JSON: /api/errors/81b00ecabfd078b6. Report an issue: GitHub.