openai-go icon indicating copy to clipboard operation
openai-go copied to clipboard

Fix shadowed err on request config execute method

Open Eduard-Voiculescu opened this issue 2 weeks ago • 0 comments

Context

The current implementation when calling RequestConfig.Execute will eventually call the handler which downstream calls the Do method on the httpClient.

This is called multiple times as we loop over the retries. In this below case, we will shadow the err. This can causes issues as we are shadowing the err from the handler.

if cfg.Request.GetBody != nil {
	cfg.Request.Body, err = cfg.Request.GetBody()
	if err != nil {
		return err
	}
}

This PR introduces a var connErr error which is set on each call of a retry. At the end, if there is an issue, we return the connErr

Eduard-Voiculescu avatar Nov 26 '25 23:11 Eduard-Voiculescu