gofr-dev/gofr · critical
%w: deleting index: %w
Error message
%w: deleting index: %w
What it means
This is errOperation wrapped around the transport error from esapi.IndicesDeleteRequest.Do in DeleteIndex. The delete request never reached the cluster or failed at the HTTP layer: unreachable host, DNS/TLS problems, connection reset, or an expired/cancelled context.
Source
Thrown at pkg/gofr/datasource/elasticsearch/elasticsearch.go:165
return nil
}
func (c *Client) DeleteIndex(ctx context.Context, index string) error {
if strings.TrimSpace(index) == "" {
return errEmptyIndex
}
start := time.Now()
tracedCtx, span := c.addTrace(ctx, "delete-index", []string{index}, "")
req := esapi.IndicesDeleteRequest{
Index: []string{index},
}
res, err := req.Do(tracedCtx, c.client)
if err != nil {
return fmt.Errorf("%w: deleting index: %w", errOperation, err)
}
defer res.Body.Close()
if res.IsError() {
return fmt.Errorf("%w: %s", errResponse, res.String())
}
c.sendOperationStats(start, fmt.Sprintf("DELETE INDEX %s", index),
[]string{index}, "", nil, span)
return nil
}
// Search executes a query against one or more indices.
// Returns the entire response JSON as a map.
func (c *Client) Search(ctx context.Context, indices []string, query map[string]any) (map[string]any, error) {
if len(indices) == 0 {
return nil, errEmptyIndexView on GitHub (pinned to 187eb24962)
Solutions
- Confirm the cluster is reachable: curl the ES endpoint from the app host.
- Check Config.Addresses and port (9200 for HTTP).
- Verify Connect()/HealthCheck succeeded before deleting.
- Give the context a sufficient deadline; retry transient network errors with backoff.
Example fix
// before err := client.DeleteIndex(ctx, "orders-2026") // cluster not up yet in CI // after waitForElasticsearch(t) // poll HealthCheck until UP err := client.DeleteIndex(ctx, "orders-2026")
Defensive patterns
Strategy: retry
Validate before calling
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if _, err := client.HealthCheck(ctx); err != nil {
return fmt.Errorf("elasticsearch unreachable, skipping delete: %w", err)
} Try / catch
var lastErr error
for attempt := 0; attempt < 3; attempt++ {
err := client.DeleteIndex(ctx, index)
if err == nil {
return nil
}
lastErr = err
if strings.Contains(err.Error(), "deleting index:") && isTransient(err) {
time.Sleep(time.Duration(attempt+1) * time.Second)
continue
}
break
}
return lastErr Prevention
- Gate index deletion behind explicit checks that the cluster is reachable.
- In CI, wait for the ES service to be healthy before running cleanup.
- Use generous context deadlines; deleting large indices can take time.
- Log and inspect the inner transport error to distinguish refused/DNS/timeout.
When it happens
Trigger: Calling DeleteIndex when the ES host is unreachable or down, network/firewall drops the connection, Connect() failed earlier leaving a broken client, or the provided context times out mid-request.
Common situations: Developers hit this during teardown/cleanup jobs after the cluster was stopped, in CI where the ES service container isn't ready yet, or with misconfigured Addresses (wrong host/port).
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- %w: creating index: %w
- %w: executing bulk: %w
- %w: executing search: %w
- failed to dial FTP server %q: %w
- connection error
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/997880036774e86b.
Report an issue: GitHub.