{"record":{"id":"aa65931b29a79604","repo":"gofr-dev/gofr","slug":"index-name-cannot-be-empty","errorCode":null,"errorMessage":"index name cannot be empty","messagePattern":"index name cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/elasticsearch/elasticsearch.go","lineNumber":25,"sourceCode":"\t\"errors\"\n\t\"fmt\"\n\t\"strings\"\n\t\"time\"\n\n\tes \"github.com/elastic/go-elasticsearch/v8\"\n\t\"github.com/elastic/go-elasticsearch/v8/esapi\"\n\t\"go.opentelemetry.io/otel/attribute\"\n\t\"go.opentelemetry.io/otel/trace\"\n)\n\nconst (\n\tstatusDown     = \"DOWN\"\n\tstatusUp       = \"UP\"\n\tdefaultTimeout = 5 * time.Second\n)\n\nvar (\n\terrEmptyIndex        = errors.New(\"index name cannot be empty\")\n\terrEmptyDocumentID   = errors.New(\"document ID cannot be empty\")\n\terrEmptyQuery        = errors.New(\"query cannot be empty\")\n\terrEmptyOperations   = errors.New(\"operations cannot be empty\")\n\terrHealthCheckFailed = errors.New(\"elasticsearch health check failed\")\n\terrOperation         = errors.New(\"elasticsearch operation error\")\n\terrMarshaling        = errors.New(\"error marshaling data\")\n\terrParsingResponse   = errors.New(\"error parsing response\")\n\terrResponse          = errors.New(\"invalid elasticsearch response\")\n\terrEncodingOperation = errors.New(\"error encoding operation\")\n)\n\n// Config holds the configuration for connecting to Elasticsearch.\ntype Config struct {\n\tAddresses []string\n\tUsername  string\n\tPassword  string\n}\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/elasticsearch/elasticsearch.go#L7-L43","documentation":"When the path contains '[', extractArrayClaim expects the suffix to be well-formed array notation like \"[0]\" (must start with '[' and end with ']'). Anything else (e.g. \"roles[\", \"roles0]\", \"roles[a][b]\") returns errInvalidArrayNotation with the full path. The bracket only marks where parsing starts, so malformed syntax after it fails here.","triggerScenarios":"Passing a claim path such as \"roles[\" or \"roles]\" or \"roles[a]\" to extractClaimValue/extractRoleFromJWT; concatenated path strings built dynamically where the index fragment got mangled.","commonSituations":"Hand-written claim paths in config; string templating that dropped the closing bracket; someone used dot-notation-only syntax but accidentally included a stray bracket.","solutions":["Correct the path to the documented form key[INDEX], e.g. \"roles[0]\"","Validate claim paths at startup with a small regex like ^[A-Za-z0-9_]+(\\[[0-9]+\\])?$ before wiring the middleware","If the value is not actually an array, drop the bracket and use a simple or dotted path instead"],"exampleFix":"// before\nextractClaimValue(claims, \"roles[0\")\n// after\nextractClaimValue(claims, \"roles[0]\")","handlingStrategy":"validation","validationCode":"var claimPathRe = regexp.MustCompile(`^[A-Za-z0-9_.]+(\\[[0-9]+\\])?$`)\nif !claimPathRe.MatchString(path) {\n    return fmt.Errorf(\"invalid claim path syntax: %q\", path)\n}","typeGuard":null,"tryCatchPattern":"v, err := extractClaimValue(claims, path)\nif errors.Is(err, errInvalidArrayNotation) {\n    // fix config; log path and fail closed\n}","preventionTips":["Use the documented forms only: \"key\", \"key[0]\", \"a.b.c\", combinations thereof","Keep claim paths in reviewed config, not ad-hoc strings at call sites","Test path parsing at startup with table-driven tests"],"tags":["jwt","rbac","parsing"],"backgroundTag":"invalid-claim-path-syntax","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}