{"id":"0f3f47a63ed6eac1","repo":"gofiber/fiber","slug":"errinvalididempotencykey","errorCode":"ErrInvalidIdempotencyKey","errorMessage":"%w: invalid length: %d != %d","messagePattern":"%w: invalid length: (.+?) != (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"middleware/idempotency/config.go","lineNumber":69,"sourceCode":"\t// DisableValueRedaction turns off masking idempotency keys in logs and errors when set to true.\n\t//\n\t// Optional. Default: false\n\tDisableValueRedaction bool\n}\n\n// ConfigDefault is the default config\nvar ConfigDefault = Config{\n\tNext: func(c fiber.Ctx) bool {\n\t\t// Skip middleware if the request was done using a safe HTTP method\n\t\treturn fiber.IsMethodSafe(c.Method())\n\t},\n\n\tLifetime: 30 * time.Minute,\n\n\tKeyHeader: \"X-Idempotency-Key\",\n\tKeyHeaderValidate: func(k string) error {\n\t\tif l, wl := len(k), 36; l != wl { // UUID length is 36 chars\n\t\t\treturn fmt.Errorf(\"%w: invalid length: %d != %d\", ErrInvalidIdempotencyKey, l, wl)\n\t\t}\n\n\t\treturn nil\n\t},\n\n\tKeepResponseHeaders: nil,\n\n\tLock: nil, // Set in configDefault so we don't allocate data here.\n\n\tStorage:               nil, // Set in configDefault so we don't allocate data here.\n\tDisableValueRedaction: false,\n}\n\n// Helper function to set default values\nfunc configDefault(config ...Config) Config {\n\t// Return default config if nothing provided\n\tif len(config) < 1 {\n\t\tcfg := ConfigDefault","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/middleware/idempotency/config.go#L51-L87","documentation":"Returned by the default KeyHeaderValidate (config.go:67-70) when the Idempotency-Key header is not exactly 36 characters (the length of a canonical UUID). The middleware propagates it to the client as the request error. It wraps ErrInvalidIdempotencyKey with the observed vs expected lengths.","triggerScenarios":"A non-safe HTTP request (POST/PUT/PATCH/DELETE — Next skips only safe methods) carries an X-Idempotency-Key header whose length is not 36: e.g. a short counter ('1', '42'), a UUID without hyphens (32 chars), a UUID with braces, or a ULID/snowflake.","commonSituations":"Client library generates non-UUID request IDs; frontend sends its internal trace ID instead of a UUID; testing with hardcoded short keys; an older client format being migrated.","solutions":["Send a RFC-4122 UUID v4 (with hyphens, 36 chars) in the X-Idempotency-Key header.","Override Config.KeyHeaderValidate to accept your existing ID format instead of UUID length.","If migrating ID formats, accept both old and new inside a custom KeyHeaderValidate."],"exampleFix":"// before — short client-generated key\nc.Req.Header.Set(\"X-Idempotency-Key\", \"order-123\")\n\n// after — full UUID\nimport \"github.com/google/uuid\"\nc.Req.Header.Set(\"X-Idempotency-Key\", uuid.NewString())\n\n// or relax the validator in the server\napp.Use(idempotency.New(idempotency.Config{\n    KeyHeaderValidate: func(k string) error {\n        if k == \"\" || len(k) > 128 { return idempotency.ErrInvalidIdempotencyKey }\n        return nil\n    },\n}))","handlingStrategy":"validation","validationCode":"// client-side: only send canonical UUIDs\nimport \"github.com/google/uuid\"\n\nfunc idempotencyKey() string {\n    return uuid.NewString() // always 36 chars\n}\n\n// server-side: accept your real ID format\napp.Use(idempotency.New(idempotency.Config{\n    KeyHeaderValidate: func(k string) error {\n        if len(k) == 0 || len(k) > 128 {\n            return idempotency.ErrInvalidIdempotencyKey\n        }\n        return nil\n    },\n}))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize client libraries on UUID v4 for idempotency keys.","Override KeyHeaderValidate whenever your ID format is not UUID-length.","Return 422 (not 500) to clients so they retry with a valid key."],"tags":["idempotency","validation","uuid","header"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}