zincsearch/zincsearch · error

GetBoolFromMap: value [%s] shuld be a bool

Error message

GetBoolFromMap: value [%s] shuld be a bool

What it means

GetBoolFromMap found the requested key but its value is not a bool. The message (which contains a typo: "shuld") prints the key name so you can locate the offending field. JSON configs frequently carry booleans as strings ("true") which will fail this assertion. Fix the value's type in the settings map.

Source

Thrown at pkg/zutils/map.go:40

	if err != nil {
		return "", fmt.Errorf("GetStringFromMap: key [%s] not found", key)
	}
	vs, ok := v.(string)
	if !ok {
		return "", fmt.Errorf("GetStringFromMap: value [%s] should be a string", key)
	}

	return vs, nil
}

func GetBoolFromMap(m interface{}, key string) (bool, error) {
	v, err := GetAnyFromMap(m, key)
	if err != nil {
		return false, fmt.Errorf("GetBoolFromMap: key [%s] not found", key)
	}
	vs, ok := v.(bool)
	if !ok {
		return false, fmt.Errorf("GetBoolFromMap: value [%s] shuld be a bool", key)
	}

	return vs, nil
}

func GetFloatFromMap(m interface{}, key string) (float64, error) {
	v, err := GetAnyFromMap(m, key)
	if err != nil {
		return 0, fmt.Errorf("GetFloatFromMap: key [%s] not found", key)
	}
	vs, ok := v.(float64)
	if !ok {
		return 0, fmt.Errorf("GetFloatFromMap: value [%s] should be a float64", key)
	}

	return vs, nil
}

View on GitHub (pinned to dd2f8afd65)

Solutions

  1. Change the key's value to a real boolean (unquoted true/false) in the settings map.
  2. If the value is the string "true"/"false", convert it with strconv.ParseBool before building the map.
  3. If you control the code path, accept both and normalize with a tolerant helper.

Example fix

// before
{"type": "dict", "suppress": "true"}

// after
{"type": "dict", "suppress": true}
Defensive patterns

Strategy: type-guard

Validate before calling

func normalizeBool(m map[string]interface{}, key string) {
    if s, ok := m[key].(string); ok {
        if b, err := strconv.ParseBool(s); err == nil {
            m[key] = b
        }
    }
}

Type guard

func isBool(v interface{}) bool { _, ok := v.(bool); return ok }

Try / catch

v, err := zutils.GetBoolFromMap(settings, "suppress")
if err != nil {
    if strings.Contains(err.Error(), "shuld be a bool") {
        return fmt.Errorf("field 'suppress' must be unquoted true/false, got %T", settings["suppress"])
    }
    return err
}

Prevention

When it happens

Trigger: Calling GetBoolFromMap via NewRegexpAnalyzer, NewDictTokenFilter, or an anonymous parse func where the key exists but holds e.g. the string "true", an int 1, or null instead of a JSON boolean.

Common situations: Hand-written configs quoting booleans ("case_sensitive": "true"); configs generated from form inputs that yield strings; YAML/JSON round-trips that turned bools into strings.

Related errors


AI-assisted analysis of zincsearch/zincsearch@dd2f8afd65 (2026-09-03). Data as JSON: /api/errors/a55c5c1eccd6b2c6. Report an issue: GitHub.