onnela-lab / forest

Forest is a library for analyzing smartphone-based high-throughput digital phenotyping data
https://forest.beiwe.org
BSD 3-Clause "New" or "Revised" License
28 stars 16 forks source link

Proposal: New error class for indicating bad data (and maybe other specific runtime errors) #239

Open biblicabeebli opened 8 months ago

biblicabeebli commented 8 months ago

This is coming from glancing at the code changes in https://github.com/onnela-lab/forest/pull/237, specifically https://github.com/onnela-lab/forest/pull/237/commits/ebebb5f21e015588e21974f88cc6e9549c0397f0

I think it just makes sense to have a well named error class that informs the user that nothing actually went wrong, but Forest cannot continue with the data or parameters as they were provided.

My use case comes from running Forest on a server and needing to display a status page/message. If I can catch a couple Forest-specific error types I can show a custom message for each.

If something is ambiguous the developer can use exception chaining to preserve the original stack trace. (Exception chaining is just when you are inside a try-except and tack on a "from" argument like raise MyNewError("information") from source_error.)

I can immediately think of two exception types, Data and Parameter:

Are there any other scenarios or special cases where a new reserved exception type like those two would be useful?