{"record":{"id":"1ce87b625a352b25","repo":"gofr-dev/gofr","slug":"w-deleting-document-w","errorCode":null,"errorMessage":"%w: deleting document: %w","messagePattern":"%w: deleting document: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/elasticsearch/documents.go","lineNumber":164,"sourceCode":"\t\treturn errEmptyIndex\n\t}\n\n\tif strings.TrimSpace(id) == \"\" {\n\t\treturn errEmptyDocumentID\n\t}\n\n\tstart := time.Now()\n\n\ttracedCtx, span := c.addTrace(ctx, \"delete-document\", []string{index}, id)\n\n\treq := esapi.DeleteRequest{\n\t\tIndex:      index,\n\t\tDocumentID: id,\n\t}\n\n\tres, err := req.Do(tracedCtx, c.client)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%w: deleting document: %w\", errOperation, err)\n\t}\n\n\tdefer res.Body.Close()\n\n\tif res.IsError() {\n\t\treturn fmt.Errorf(\"%w: %s\", errResponse, res.String())\n\t}\n\n\tc.sendOperationStats(start, fmt.Sprintf(\"DELETE DOCUMENT %s/%s\", index, id),\n\t\t[]string{index}, id, nil, span)\n\n\treturn nil\n}\n","sourceCodeStart":146,"sourceCodeEnd":178,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/elasticsearch/documents.go#L146-L178","documentation":"extractClaimValue resolves a dotted/indexed path (e.g. \"role\", \"roles[0]\", \"permissions.role\") inside the JWT MapClaims to fetch the role. The library throws errEmptyClaimPath when the configured claim path string is empty, because there is no way to look up a claim without a key. It is a configuration/programming error, not a token problem.","triggerScenarios":"Calling extractClaimValue (directly or via extractRoleFromJWT) with path == \"\" — typically because the RBAC middleware option that sets the role claim path was never set or was set to an empty string.","commonSituations":"Constructing rbac middleware options with a zero-valued struct field; reading the claim-path from an env var or config file that is missing/empty; forgetting to call the option that configures the role claim name after a library version upgrade renamed the option.","solutions":["Set the role claim path explicitly in the RBAC middleware options (e.g. Options/WithRoleClaim(\"role\")) so it is never empty","If the path comes from config/env, fail fast at startup: validate it is non-empty before wiring the middleware","Guard the call site: skip/short-circuit extraction when the configured path is \"\" and return a clear configuration error"],"exampleFix":"// before\nmw := rbac.New(h, roles) // roleClaimPath left empty\n// after\nmw := rbac.New(h, roles, rbac.WithRoleClaimPath(\"role\"))","handlingStrategy":"validation","validationCode":"if claimPath == \"\" {\n    return nil, fmt.Errorf(\"rbac: role claim path must be configured\")\n}\n// wire middleware only after this check passes","typeGuard":null,"tryCatchPattern":"v, err := extractClaimValue(claims, path)\nif errors.Is(err, errEmptyClaimPath) {\n    // programmer/config error: fail startup or request with 500\n}","preventionTips":["Always pass the claim path via an explicit option/constructor argument, never a zero-valued field","Validate config (env/flags) at boot: non-empty claim path is a startup precondition","Add a unit test asserting middleware construction fails fast on an empty claim path"],"tags":["jwt","rbac","configuration"],"backgroundTag":"empty-claim-path","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}