{"record":{"id":"df572627d71fbdf8","repo":"gofr-dev/gofr","slug":"w-got-v","errorCode":null,"errorMessage":"%w, got: %v","messagePattern":"%w, got: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/service/connection_pool.go","lineNumber":65,"sourceCode":"\t// IdleConnTimeout is the maximum amount of time an idle (keep-alive) connection will remain\n\t// idle before closing itself.\n\t// If not explicitly set (0), a default of 90 seconds will be used.\n\t// Negative values will cause validation error.\n\tIdleConnTimeout time.Duration\n}\n\n// Validate checks if the connection pool configuration values are valid.\nfunc (c *ConnectionPoolConfig) Validate() error {\n\tif c.MaxIdleConns < 0 {\n\t\treturn fmt.Errorf(\"%w, got: %d\", errNegativeMaxIdleConns, c.MaxIdleConns)\n\t}\n\n\tif c.MaxIdleConnsPerHost < 0 {\n\t\treturn fmt.Errorf(\"%w, got: %d\", errNegativeMaxIdleConnsPerHost, c.MaxIdleConnsPerHost)\n\t}\n\n\tif c.IdleConnTimeout < 0 {\n\t\treturn fmt.Errorf(\"%w, got: %v\", errNegativeIdleConnTimeout, c.IdleConnTimeout)\n\t}\n\n\treturn nil\n}\n\n// AddOption implements the Options interface to apply connection pool configuration to HTTP service.\n// It modifies the underlying HTTP client's transport to use optimized connection pool settings.\nfunc (c *ConnectionPoolConfig) AddOption(h HTTP) HTTP {\n\t// Extract the base httpService from any wrapped service\n\thttpSvc := extractHTTPService(h)\n\tif httpSvc == nil {\n\t\t// If we can't find the base service, return unchanged\n\t\t// This maintains backward compatibility\n\t\treturn h\n\t}\n\n\t// Validate configuration before applying\n\tif err := c.Validate(); err != nil {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/service/connection_pool.go#L47-L83","documentation":"This is the wrapped form of errNegativeIdleConnTimeout from (*ConnectionPoolConfig).Validate, formatted with %w (errors.Is-compatible) and %v to include the offending time.Duration (e.g. \"got: -5s\"). It blocks applying an invalid keep-alive duration to the HTTP transport.","triggerScenarios":"Validate() (directly or via AddOption/AddHTTPService) encounters c.IdleConnTimeout < 0, e.g. ConnectionPoolConfig{IdleConnTimeout: -time.Minute}.Validate().","commonSituations":"Duration parsing mistakes (missing unit, sign typo) in config/env; using -1 as a sentinel for 'no timeout' which the library does not support; overflow in duration arithmetic.","solutions":["Use 0 (default) or a positive duration for IdleConnTimeout; never negative","Parse with time.ParseDuration and check sign immediately after loading config","Clamp: if d < 0 { d = 0 } before building ConnectionPoolConfig","Match with errors.Is(err, errNegativeIdleConnTimeout) for field-specific handling"],"exampleFix":"// before\npool := &ConnectionPoolConfig{IdleConnTimeout: timeout} // timeout = -30s from config\n// after\ntimeout, _ := time.ParseDuration(cfg.IdleTimeout)\nif timeout < 0 { timeout = 0 }\npool := &ConnectionPoolConfig{IdleConnTimeout: timeout}","handlingStrategy":"validation","validationCode":"d, err := time.ParseDuration(cfg.IdleTimeout)\nif err != nil { return err }\nif d < 0 { return fmt.Errorf(\"IdleConnTimeout must be >= 0, got %v\", d) }\npool := &ConnectionPoolConfig{IdleConnTimeout: d}","typeGuard":"func isNegativeIdleTimeoutErr(err error) bool { return errors.Is(err, errNegativeIdleConnTimeout) }","tryCatchPattern":"if err := pool.Validate(); err != nil {\n    if isNegativeIdleTimeoutErr(err) {\n        pool.IdleConnTimeout = 0 // fall back to transport default\n    } else {\n        return fmt.Errorf(\"connection pool config: %w\", err)\n    }\n}","preventionTips":["Never encode 'no timeout' as a negative duration; use 0","Parse and sign-check durations immediately after reading config","Validate the full config before applying it to a service","Use errors.Is(err, errNegativeIdleConnTimeout) and log the offending duration ('got: %v')"],"tags":["http-client","configuration","connection-pool","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}