"expected" vs "unexpected" exceptions in dnadna commands
Currently, when any unhandled exception occurs in the code, the command-line interface handles this by outputting a message like:
an unexpected error occurred: blah blah blah; run again with --debug to view the full traceback or with --pdb to drop into a debugger
This has bothered me for a while, because it's indiscriminate. Some errors are expected in that they have been anticipated by us, the developers. These are mostly exceptions we raise explicitly, such as when there are errors in a config file, or any other exceptions that can occur in the code that we expect might happen and have written custom error messages for.
The "unexpected exception" is more for when some error occurred that we do not have explicit handling for.
In both cases I think the mention of the --debug
flag can be helpful, but in the case of "anticipated" errors I think we can provide a still friendlier message.
This means needing a way to distinguish between exceptions (the CLI takes any uncaught exception and handles it as above). To do this we need a DNADNAException
base class for all exceptions that we raise explicitly. In this cases we can provide better error messages as well.
One common area of unhandled exceptions has usually be in network code. When evaluating the net on some input we could provide better exception handling, and hence a more useful error message (e.g. indicating to the user more explicitly where their code failed).
We can't anticipate every possible error in network evaluation, but there are probably some where we could do better. There are also probably some areas where we could perform better validation in the first place to ensure that networks don't blow up.