@@ -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
295302func 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 }
0 commit comments