{"id":"5f36019421784671","repo":"labstack/echo","slug":"echo-key-auth-middleware-could-not-create-extracto","errorCode":null,"errorMessage":"echo key-auth middleware could not create extractors from KeyLookup string","messagePattern":"echo key-auth middleware could not create extractors from KeyLookup string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/key_auth.go","lineNumber":156,"sourceCode":"func (config KeyAuthConfig) ToMiddleware() (echo.MiddlewareFunc, error) {\n\tif config.Skipper == nil {\n\t\tconfig.Skipper = DefaultKeyAuthConfig.Skipper\n\t}\n\tif config.KeyLookup == \"\" {\n\t\tconfig.KeyLookup = DefaultKeyAuthConfig.KeyLookup\n\t}\n\tif config.Validator == nil {\n\t\treturn nil, errors.New(\"echo key-auth middleware requires a validator function\")\n\t}\n\n\tlimit := cmp.Or(config.AllowedCheckLimit, 1)\n\n\textractors, cErr := createExtractors(config.KeyLookup, limit)\n\tif cErr != nil {\n\t\treturn nil, fmt.Errorf(\"echo key-auth middleware could not create key extractor: %w\", cErr)\n\t}\n\tif len(extractors) == 0 {\n\t\treturn nil, errors.New(\"echo key-auth middleware could not create extractors from KeyLookup string\")\n\t}\n\n\treturn func(next echo.HandlerFunc) echo.HandlerFunc {\n\t\treturn func(c *echo.Context) error {\n\t\t\tif config.Skipper(c) {\n\t\t\t\treturn next(c)\n\t\t\t}\n\n\t\t\tvar lastExtractorErr error\n\t\t\tvar lastValidatorErr error\n\t\t\tfor _, extractor := range extractors {\n\t\t\t\tkeys, source, extrErr := extractor(c)\n\t\t\t\tif extrErr != nil {\n\t\t\t\t\tlastExtractorErr = extrErr\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfor _, key := range keys {\n\t\t\t\t\tvalid, err := config.Validator(c, key, source)","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/labstack/echo/blob/05489dc1730161df26b72d1ae2a3ba6fb8178fc7/middleware/key_auth.go#L138-L174","documentation":"Returned by KeyAuthConfig.ToMiddleware when createExtractors parsed the KeyLookup string without error but produced zero extractors. Each extractor reads the key from a source (header/query/form/cookie); having none means the middleware has nowhere to look. It is a defensive guard for malformed KeyLookup strings that the parser silently accepted.","triggerScenarios":"Setting config.KeyLookup to a string that produces no usable extractor sources (e.g., a source prefix that is not header/query/form/cookie, or a degenerate comma-separated list). Note: an empty KeyLookup is replaced by the default, so you must explicitly pass a malformed string.","commonSituations":"Typos in the KeyLookup source prefix (e.g., \"headers:Authorization\" instead of \"header:Authorization\"), or hand-building a multi-source lookup string with a stray comma/empty segment.","solutions":["Use a supported source prefix: \"header:<name>\", \"header:<name>:<cut-prefix>\", \"query:<name>\", \"form:<name>\", or \"cookie:<name>\".","For multiple sources use the comma form, e.g. \"header:Authorization,header:X-Api-Key\".","If unsure, omit KeyLookup entirely to use the default \"header:Authorization:Bearer \".","Call config.ToMiddleware() to inspect the error instead of panicking."],"exampleFix":"// before\nm := middleware.KeyAuthWithConfig(middleware.KeyAuthConfig{\n    KeyLookup: \"headers:X-Api-Key\", // typo: 'headers' is not a valid source\n    Validator: myValidator,\n})\n// after\nm := middleware.KeyAuthWithConfig(middleware.KeyAuthConfig{\n    KeyLookup: \"header:X-Api-Key\",\n    Validator: myValidator,\n})","handlingStrategy":"validation","validationCode":"var validSources = map[string]bool{\"header\": true, \"query\": true, \"form\": true, \"cookie\": true}\n\nfunc validKeyLookup(s string) bool {\n    for _, part := range strings.Split(s, \",\") {\n        src, _, _ := strings.Cut(strings.TrimSpace(part), \":\")\n        if !validSources[src] { return false }\n    }\n    return true\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use supported source prefixes: header, query, form, cookie.","If unsure, omit KeyLookup to use the default \"header:Authorization:Bearer \".","Validate multi-source strings before wiring; each comma-separated segment needs a valid prefix."],"tags":["middleware","key-auth","config","panic","startup"],"analyzedSha":"05489dc1730161df26b72d1ae2a3ba6fb8178fc7","analyzedAt":"2026-08-04T21:32:47.783Z","schemaVersion":2}