dsa-ou / algoesup

Algorithmic essays support: examples, templates, guides, library
https://dsa-ou.github.io/algoesup/
BSD 3-Clause "New" or "Revised" License
2 stars 0 forks source link

Improve error handling #8

Closed densnow closed 5 months ago

densnow commented 9 months ago

Since time_it(), time_cases(), and time_functions() are higher-order functions, the source of any errors can be obscured.

To make it easier for the user to trace errors, we can catch exceptions and print additional information about the state of any functions involved in the error.

It might be best to catch exceptions in time_it() like the following

except Exception as e:
    print(f"Error occurred in time_it with function {function.__name__} and args {args}:\n {e}")

and then in time_cases() like:

except Exception as e:
    print(f"An error occurred in test case {cases[index].__name__} with size {size}:\n {e}")

And something similar in time_functions(). The exact details might need to change, but the idea is to pass on specific information about the state of the arguments that could be useful.

mwermelinger commented 9 months ago

Good idea. Could you please liaise with Steve about the errors he had and then work on this?

mwermelinger commented 8 months ago

Additionally, there should be a message if the %linter on command can't run the corresponding linter.

densnow commented 8 months ago

Looking at the ruff docs regarding exit codes it returns:

This explains why we cannot just use the check=True option in subprocess.run in %ruff. If we want to distinguish between violations and abnormal termination we have to check the returncode attribute of the result from subprocess.run()

mwermelinger commented 8 months ago

To summarise so far:

For the latter, would be good to catch the subprocess exit code and handle it appropriately.

mwermelinger commented 7 months ago

The linter errors are dealt as part of #29.