{"record":{"id":"8b35197bb5889610","repo":"zincsearch/zincsearch","slug":"getfloatfrommap-key-s-not-found","errorCode":null,"errorMessage":"GetFloatFromMap: key [%s] not found","messagePattern":"GetFloatFromMap: key \\[(.+?)\\] not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/zutils/map.go","lineNumber":49,"sourceCode":"}\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\nfunc GetStringSliceFromMap(m interface{}, key string) ([]string, error) {\n\tv, err := GetAnyFromMap(m, key)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"GetStringSliceFromMap: key [%s] not found\", key)\n\t}\n\tvar vs []interface{}\n\tswitch v := v.(type) {\n\tcase []string:\n\t\treturn v, nil","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/zincsearch/zincsearch/blob/dd2f8afd6562d4d52c41b2c5d312280e684a25ba/pkg/zutils/map.go#L31-L67","documentation":"GetFloatFromMap reads a numeric option from a filter settings map (used by dict, edge_ngram, length, ngram, shingle, truncate filters). This error means the required key is not present at all. It is a missing-required-option error surfaced while constructing a token filter.","triggerScenarios":"Calling GetFloatFromMap via NewDictTokenFilter, NewEdgeNgramTokenFilter, NewLengthTokenFilter, NewNgramTokenFilter, NewShingleTokenFilter, or NewTruncateTokenFilter when the settings map lacks the numeric option (e.g. \"min_gram\", \"max_gram\", \"preserve_original\").","commonSituations":"Writing a token filter definition that omits a required numeric parameter (e.g. an ngram filter with no min_gram); typos in the option name; switching filter types without updating the option set.","solutions":["Add the missing numeric key (named in the error) to the filter's settings map.","Check the option name spelling against the filter's documentation.","Provide defaults for optional numeric params in a wrapper before calling the constructor.","Validate the filter definition against an expected-option schema before construction."],"exampleFix":"// before\n{\"type\": \"ngram\"}\n\n// after\n{\"type\": \"ngram\", \"min_gram\": 2, \"max_gram\": 3}","handlingStrategy":"validation","validationCode":"func requireNumeric(m map[string]interface{}, key string) error {\n    v, ok := m[key]\n    if !ok {\n        return fmt.Errorf(\"required numeric option %q missing\", key)\n    }\n    if _, ok := v.(float64); !ok {\n        return fmt.Errorf(\"option %q must be a number, got %T\", key, v)\n    }\n    return nil\n}\n// requireNumeric(settings, \"min_gram\")","typeGuard":null,"tryCatchPattern":"min, err := zutils.GetFloatFromMap(settings, \"min_gram\")\nif err != nil {\n    if strings.Contains(err.Error(), \"not found\") {\n        return fmt.Errorf(\"ngram filter requires min_gram/max_gram: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep a per-filter-type required-option checklist (e.g. ngram needs min_gram and max_gram).","Validate filter definitions against a schema before calling constructors.","Test each filter definition with a constructor call in unit tests using fixture configs.","When changing filter types, update the whole option set, not just the type field."],"tags":["config","missing-key","token-filter"],"backgroundTag":"missing-config-key","analyzedSha":"dd2f8afd6562d4d52c41b2c5d312280e684a25ba","analyzedAt":"2026-09-03T00:22:38.551Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}