gofr-dev/gofr · error
index name cannot be empty
Error message
index name cannot be empty
What it means
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.
Source
Thrown at pkg/gofr/datasource/elasticsearch/elasticsearch.go:25
"errors"
"fmt"
"strings"
"time"
es "github.com/elastic/go-elasticsearch/v8"
"github.com/elastic/go-elasticsearch/v8/esapi"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
const (
statusDown = "DOWN"
statusUp = "UP"
defaultTimeout = 5 * time.Second
)
var (
errEmptyIndex = errors.New("index name cannot be empty")
errEmptyDocumentID = errors.New("document ID cannot be empty")
errEmptyQuery = errors.New("query cannot be empty")
errEmptyOperations = errors.New("operations cannot be empty")
errHealthCheckFailed = errors.New("elasticsearch health check failed")
errOperation = errors.New("elasticsearch operation error")
errMarshaling = errors.New("error marshaling data")
errParsingResponse = errors.New("error parsing response")
errResponse = errors.New("invalid elasticsearch response")
errEncodingOperation = errors.New("error encoding operation")
)
// Config holds the configuration for connecting to Elasticsearch.
type Config struct {
Addresses []string
Username string
Password string
}
View on GitHub (pinned to 187eb24962)
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
Example fix
// before extractClaimValue(claims, "roles[0") // after extractClaimValue(claims, "roles[0]")
Defensive patterns
Strategy: validation
Validate before calling
var claimPathRe = regexp.MustCompile(`^[A-Za-z0-9_.]+(\[[0-9]+\])?$`)
if !claimPathRe.MatchString(path) {
return fmt.Errorf("invalid claim path syntax: %q", path)
} Try / catch
v, err := extractClaimValue(claims, path)
if errors.Is(err, errInvalidArrayNotation) {
// fix config; log path and fail closed
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- document ID cannot be empty
- %w: deleting document: %w
- %w: %s
- query cannot be empty
- operations cannot be empty
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/aa65931b29a79604.
Report an issue: GitHub.