{"record":{"id":"a55c5c1eccd6b2c6","repo":"zincsearch/zincsearch","slug":"getboolfrommap-value-s-shuld-be-a-bool","errorCode":null,"errorMessage":"GetBoolFromMap: value [%s] shuld be a bool","messagePattern":"GetBoolFromMap: value \\[(.+?)\\] shuld be a bool","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/zutils/map.go","lineNumber":40,"sourceCode":"\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"GetStringFromMap: key [%s] not found\", key)\n\t}\n\tvs, ok := v.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"GetStringFromMap: value [%s] should be a string\", key)\n\t}\n\n\treturn vs, nil\n}\n\nfunc GetBoolFromMap(m interface{}, key string) (bool, error) {\n\tv, err := GetAnyFromMap(m, key)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"GetBoolFromMap: key [%s] not found\", key)\n\t}\n\tvs, ok := v.(bool)\n\tif !ok {\n\t\treturn false, fmt.Errorf(\"GetBoolFromMap: value [%s] shuld be a bool\", key)\n\t}\n\n\treturn vs, nil\n}\n\nfunc GetFloatFromMap(m interface{}, key string) (float64, error) {\n\tv, err := GetAnyFromMap(m, key)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"GetFloatFromMap: key [%s] not found\", key)\n\t}\n\tvs, ok := v.(float64)\n\tif !ok {\n\t\treturn 0, fmt.Errorf(\"GetFloatFromMap: value [%s] should be a float64\", key)\n\t}\n\n\treturn vs, nil\n}\n","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/zincsearch/zincsearch/blob/dd2f8afd6562d4d52c41b2c5d312280e684a25ba/pkg/zutils/map.go#L22-L58","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Change the key's value to a real boolean (unquoted true/false) in the settings map.","If the value is the string \"true\"/\"false\", convert it with strconv.ParseBool before building the map.","If you control the code path, accept both and normalize with a tolerant helper."],"exampleFix":"// before\n{\"type\": \"dict\", \"suppress\": \"true\"}\n\n// after\n{\"type\": \"dict\", \"suppress\": true}","handlingStrategy":"type-guard","validationCode":"func normalizeBool(m map[string]interface{}, key string) {\n    if s, ok := m[key].(string); ok {\n        if b, err := strconv.ParseBool(s); err == nil {\n            m[key] = b\n        }\n    }\n}","typeGuard":"func isBool(v interface{}) bool { _, ok := v.(bool); return ok }","tryCatchPattern":"v, err := zutils.GetBoolFromMap(settings, \"suppress\")\nif err != nil {\n    if strings.Contains(err.Error(), \"shuld be a bool\") {\n        return fmt.Errorf(\"field 'suppress' must be unquoted true/false, got %T\", settings[\"suppress\"])\n    }\n    return err\n}","preventionTips":["Never quote booleans in JSON configs (\"true\" is a string, true is a bool).","Run configs through json.Unmarshal and type-check fields before use.","Normalize stringly-typed booleans with strconv.ParseBool in a preprocessing pass.","Add a schema validator (e.g. JSON Schema with type:boolean) to your config pipeline."],"tags":["config","type-mismatch","boolean"],"backgroundTag":"config-value-type-mismatch","analyzedSha":"dd2f8afd6562d4d52c41b2c5d312280e684a25ba","analyzedAt":"2026-09-03T00:22:38.551Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}