"failed" status when making OpenAI Assistant

Hello, When making assistant I am getting a failed status, so I tried to get details of this error, but couldn’t,

Starting assistant run…
Assistant run started. Run ID: run_ldxB03FREaSuY57KhJxVGegb
Run status: in_progress
Run status: in_progress
Run status: in_progress
Run status: in_progress
Run status: failed
Run failed with error: No failure details available

in

OPEN_AI_API_KEY = os.getenv("OPEN_AI_API_KEY")
client = OpenAI(api_key=OPEN_AI_API_KEY)

def run_assistant(thread):
    #Retrieve the Assistant ID from shelve (or wherever it's stored)
    with shelve.open("assistant_db") as assistant_shelf:
        assistant_id = assistant_shelf.get('assistant_id', None)

    if not assistant_id:
        raise ValueError("No assistant ID found. Please create an assistant first.")
    
    print("Starting assistant run...")
    
    # Run the assistant
    run = client.beta.threads.runs.create(
        thread_id=thread.id,
        assistant_id=assistant_id,
    )
    print(f"Assistant run started. Run ID: {run.id}")

    # Timeout mechanism to avoid infinite wait
    start_time = time.time()
    timeout = 60
    
    while run.status != "completed":
        if time.time() - start_time > timeout:
            raise TimeoutError("Assistant response took too long.")
        
        time.sleep(1)
        try:
            run = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)
            print(f"Run status: {run.status}")
            if run.status == "failed":
                failure_error = getattr(run,  'failure_message', "No failure details available")
                print(f"Run failed with error: {failure_error}")
        except Exception as e:
            print(f"Error retrieving run status: {e}")

    print("Assistant run completed.")

    try:   
        # Retrieve the Messages
        messages = client.beta.threads.messages.list(thread_id=thread.id)
        new_message = messages.data[0].content[0].text.value
        print(f"Generated message: {new_message}")
    except Exception as e:
        print(f"Error retrieving message: {e}")
    
    return new_message

Can you spot the problem?
Thank you in advance

Here’s code that will let YOU spot the problem.

Where the initial problem was not raising an exception with real error info.

from openai import OpenAI
import time
# OPEN_AI_API_KEY = os.getenv("OPEN_AI_API_KEY")

client = OpenAI(timeout=30)

class testThread():
    def __init__(self, *args):
        self.id = None

# hard-coded test values
test_assistant_id = "asst_cpbRqZ3Qvop9YZVsGvC3vIVB"
thread_obj        = testThread()
thread_obj.id     = "thread_YMebPktywhZydwgzW9HLj2Xb"

def run_assistant(thread):
    try:
        if test_assistant_id:
            assistant_id = test_assistant_id
    except NameError:
        #Retrieve the Assistant ID from shelve (or wherever it's stored)
        with shelve.open("assistant_db") as assistant_shelf:
            assistant_id = assistant_shelf.get('assistant_id', None)
    if not assistant_id:
        raise ValueError("No assistant ID obtained by run_assistant function.")
    
    print("Starting assistant run...")
    
    # Run the assistant
    run = client.beta.threads.runs.create(
        thread_id=thread.id,
        assistant_id=assistant_id,
    )
    print(f"Assistant run started. Run ID: {run.id}")

    # Timeout mechanism to avoid infinite wait
    start_time = time.time()
    timeout = 60
    
    while run.status != "completed":
        if time.time() - start_time > timeout:
            raise TimeoutError("Assistant response took too long.")
        
        time.sleep(1)
        try:
            run = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)
            print(f"Run status: {run.status}")
            if run.status == "failed":
                failure_error = run.last_error.code + " - " + run.last_error.message
                raise ValueError({failure_error})
        except Exception as e:
            print(f"Error retrieving run status: {e}")
            raise

    print("Assistant run completed.")

    try:   
        # Retrieve the Messages
        messages = client.beta.threads.messages.list(thread_id=thread.id)
        new_message = messages.data[0].content[0].text.value
        print(f"Generated message: {new_message}")
    except Exception as e:
        print(f"Error retrieving message: {e}")
    
    return new_message

if __name__ == "__main__":
    run_assistant(thread_obj)

Thank you very much, but for some some reason another error occured, but it is better than nothing.
>_<