{"record":{"id":"47afade712f5f231","repo":"gofr-dev/gofr","slug":"error-marshaling-data","errorCode":null,"errorMessage":"error marshaling data","messagePattern":"error marshaling data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/elasticsearch/elasticsearch.go","lineNumber":31,"sourceCode":"\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\n// Client represents the Elasticsearch client.\ntype Client struct {\n\tconfig  Config\n\tclient  *es.Client\n\tlogger  Logger\n\tmetrics Metrics","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/elasticsearch/elasticsearch.go#L13-L49","documentation":"While walking a dotted path, a segment key is not present in the current map (or a non-map was hit mid-path and it wasn't the last segment). The library wraps errClaimPathNotFound with the deepest resolved prefix (parts[:i+1]) to pinpoint where traversal stopped. The token parsed successfully; the configured nested path just doesn't exist in it.","triggerScenarios":"Nested path like \"permissions.role\" where \"permissions\" or \"permissions.role\" key is absent from the token; non-final segment resolving to a non-map value (handled here as the non-last-branch of the default case).","commonSituations":"Typo in nested claim path; IdP omits the nested object for some token types (client-credentials tokens often lack user claims); renaming claims during migration.","solutions":["Decode a real token and correct the nested path to the actual key chain","Require the nested claim in token issuance for all relevant clients/flows","errors.Is(err, errClaimPathNotFound) → return 401/403 and log the exact failing prefix shown in the message"],"exampleFix":"// before\nextractClaimValue(claims, \"permisions.role\") // typo\n// after\nextractClaimValue(claims, \"permissions.role\")","handlingStrategy":"try-catch","validationCode":"if _, ok := claims[\"permissions\"]; !ok {\n    return fmt.Errorf(\"nested claim permissions missing from token\")\n}","typeGuard":"func hasNestedPath(claims jwt.MapClaims, parts ...string) bool {\n    cur := claims\n    for i, p := range parts {\n        next, ok := cur[p].(map[string]any)\n        if !ok && i < len(parts)-1 { return false }\n        if i == len(parts)-1 { _, ok := cur[p]; return ok }\n        cur = jwt.MapClaims(next)\n    }\n    return false\n}","tryCatchPattern":"v, err := extractClaimValue(claims, \"permissions.role\")\nif errors.Is(err, errClaimPathNotFound) {\n    http.Error(w, \"missing claim: \"+err.Error(), http.StatusUnauthorized)\n    return\n}","preventionTips":["Copy nested paths from a decoded real token, never from memory","Require the nested object in the issuer's claim filters for all clients","Log the failing prefix from the error message to speed up config fixes"],"tags":["jwt","rbac","claims"],"backgroundTag":"jwt-claim-not-found","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}