{"record":{"id":"896769c36d4f5034","repo":"gofr-dev/gofr","slug":"unexpected-result-type-from-circuit-breaker","errorCode":null,"errorMessage":"unexpected result type from circuit breaker","messagePattern":"unexpected result type from circuit breaker","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/service/circuit_breaker.go","lineNumber":20,"sourceCode":"\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"net/http\"\n\t\"sync\"\n\t\"time\"\n)\n\n// circuitBreaker states.\nconst (\n\tClosedState = iota\n\tOpenState\n)\n\nvar (\n\t// ErrCircuitOpen indicates that the circuit breaker is open.\n\tErrCircuitOpen                        = errors.New(\"unable to connect to server at host\")\n\tErrUnexpectedCircuitBreakerResultType = errors.New(\"unexpected result type from circuit breaker\")\n)\n\n// CircuitBreakerConfig holds the configuration for the circuitBreaker.\ntype CircuitBreakerConfig struct {\n\tThreshold int           // Threshold represents the max no of retry before switching the circuit breaker state.\n\tInterval  time.Duration // Interval represents the time interval duration between hitting the HealthURL\n}\n\n// circuitBreaker represents a circuit breaker implementation.\ntype circuitBreaker struct {\n\tmu           sync.RWMutex\n\tstate        int // ClosedState or OpenState\n\tfailureCount int\n\tthreshold    int\n\tinterval     time.Duration\n\tlastChecked  time.Time\n\tmetrics      Metrics\n\tserviceName  string","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/service/circuit_breaker.go#L2-L38","documentation":"ErrUnexpectedCircuitBreakerResultType is returned by (*circuitBreaker).handleCircuitBreakerResult when the value stored in the breaker's result channel is not an *http.Response even though err was nil. It guards the internal goroutine/typed-result contract of the circuit breaker implementation.","triggerScenarios":"executeWithCircuitBreaker submits the request to the breaker, whose internal result comes back through an any-typed channel; a failed type assertion result.(*http.Response) with err==nil makes handleCircuitBreakerResult return this error. In practice it indicates an internal bug or misuse of the breaker's execution path rather than a caller mistake.","commonSituations":"Concurrent modifications or custom code paths feeding unexpected values into the breaker's result; library upgrades that changed the internal result contract; race conditions between the request goroutine and the breaker state machine.","solutions":["Pin/upgrade to a gofr version where the circuit breaker result type is consistent; check the changelog for circuit_breaker.go fixes","Don't call the breaker's internals directly — always go through the service's doRequest/executeWithCircuitBreaker API","If reproducible, file a bug with a minimal reproduction including the CircuitBreakerConfig and call pattern","Wrap the call and use errors.Is(err, ErrUnexpectedCircuitBreakerResultType) to distinguish it from real network failures"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"resp, err := svc.doRequest(ctx, req)\nif errors.Is(err, ErrUnexpectedCircuitBreakerResultType) {\n    // internal breaker contract violation: treat as non-retryable bug\n}","typeGuard":"func isUnexpectedBreakerResult(err error) bool { return errors.Is(err, ErrUnexpectedCircuitBreakerResultType) }","tryCatchPattern":"resp, err := svc.Get(ctx, url)\nif err != nil {\n    if errors.Is(err, ErrUnexpectedCircuitBreakerResultType) {\n        log.Error(\"circuit breaker returned invalid result; report bug\")\n        return err // do not retry\n    }\n    return err\n}","preventionTips":["Only use the public service API (doRequest/Get/Post), never breaker internals","Keep gofr updated; check changelog for circuit breaker fixes","If reproducible, file a minimal reproduction bug with your CircuitBreakerConfig","Distinguish this sentinel from ErrCircuitOpen in error handling branches"],"tags":["circuit-breaker","http-client","type-assertion","resilience"],"backgroundTag":"unexpected-result-type","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}