Skip to content

Missing Error Handling in asyncio.run Method #989

@chakravarthik27

Description

@chakravarthik27

Description

The provided code snippet lacks error handling techniques within the asyncio.run method, which can lead to unhandled exceptions and potential program crashes. Specifically, if any errors occur during the execution of asynchronous tasks initiated by asyncio.run, they are not caught or handled appropriately.

Code Snippet:

async_tests = TestFactory.async_run(samples_list, model_handler, **kwargs)
temp_res = asyncio.run(async_tests)
results = []
for each in temp_res:
    if hasattr(each, "_result"):
        results.extend(each._result)
    elif isinstance(each, list):
        for i in each:
            if hasattr(i, "_result"):
                results.extend(i._result)
            else:
                results.append(i)

return results

Proposed Solution:

Implement error-catching techniques within the asyncio.run method to handle exceptions gracefully. This can prevent crashes and provide better error reporting to aid in debugging.

Suggested Changes:

  1. Surround the asyncio.run call with a try-except block to catch any exceptions raised during asynchronous execution.
  2. Provide appropriate error handling within the except block, such as logging the error or returning an error message.
  3. Ensure that the error handling mechanism does not disrupt the flow of the program and allows it to gracefully handle errors while continuing execution.

Image

Metadata

Metadata

Labels

v2.1.0Issue or request to be done in v2.1.0 release🐛 BugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions