Skip to content

Commit 73a6511

Browse files
committed
updated go files
1 parent f7bfeaf commit 73a6511

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

internal/provider/resource_openai_vector_store_file.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ func resourceOpenAIVectorStoreFileCreate(ctx context.Context, d *schema.Resource
269269
return resourceOpenAIVectorStoreFileReadWithRetry(ctx, d, m, 5)
270270
}
271271

272+
// containsRetriableError checks if an error message indicates a retriable error.
273+
// Uses case-insensitive matching to catch "404 Not Found", "No file found", etc.
274+
func containsRetriableError(message string) bool {
275+
lowerMsg := strings.ToLower(message)
276+
return strings.Contains(lowerMsg, "no file found") || strings.Contains(lowerMsg, "not found")
277+
}
278+
272279
// resourceOpenAIVectorStoreFileReadWithRetry attempts to read the vector store file with retry logic
273280
// to handle eventual consistency issues with the OpenAI API.
274281
//
@@ -293,6 +300,11 @@ func resourceOpenAIVectorStoreFileCreate(ctx context.Context, d *schema.Resource
293300
// - nil diagnostics on success
294301
// - diagnostics with error details if all retries are exhausted or non-retriable error occurs
295302
func resourceOpenAIVectorStoreFileReadWithRetry(ctx context.Context, d *schema.ResourceData, m interface{}, maxRetries int) diag.Diagnostics {
303+
// Validate maxRetries configuration
304+
if maxRetries <= 0 {
305+
return diag.Errorf("maxRetries must be at least 1 for vector store file read retries")
306+
}
307+
296308
var lastErr diag.Diagnostics
297309

298310
for attempt := 0; attempt < maxRetries; attempt++ {
@@ -312,12 +324,7 @@ func resourceOpenAIVectorStoreFileReadWithRetry(ctx context.Context, d *schema.R
312324
// Use case-insensitive matching to catch "404 Not Found", "No file found", etc.
313325
shouldRetry := false
314326
for _, diag := range diags {
315-
summary := strings.ToLower(diag.Summary)
316-
detail := strings.ToLower(diag.Detail)
317-
if strings.Contains(summary, "no file found") ||
318-
strings.Contains(detail, "no file found") ||
319-
strings.Contains(summary, "not found") ||
320-
strings.Contains(detail, "not found") {
327+
if containsRetriableError(diag.Summary) || containsRetriableError(diag.Detail) {
321328
shouldRetry = true
322329
break
323330
}

internal/provider/resource_openai_vector_store_file_retry_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,6 @@ func simulateRetryLogic(readFunc mockReadFunc, maxRetries int) diag.Diagnostics
208208
return lastErr
209209
}
210210

211-
// containsRetriableError checks if an error message indicates a retriable error
212-
// Uses case-insensitive matching to catch "404 Not Found", "No file found", etc.
213-
func containsRetriableError(message string) bool {
214-
lowerMsg := strings.ToLower(message)
215-
return strings.Contains(lowerMsg, "no file found") || strings.Contains(lowerMsg, "not found")
216-
}
217-
218211
// BenchmarkRetryLogic benchmarks the retry logic performance
219212
func BenchmarkRetryLogic(b *testing.B) {
220213
mockRead := func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {

0 commit comments

Comments
 (0)