In the past, MCprep used many methods to determine if an error occurred somewhere outside an operator, such as checking for None, using 1 to signify an exception, etc. These methods have the following issues though:
Not descriptive for the caller; the caller knows an error occurred somewhere, but doesn't know where. This makes it difficult to create a well crafted error message, which makes errors harder to troubleshoot
Inconsistent, which makes MCprep's code harder to understand.
To mitigate these issues in new code, a new error class is needed. This PR introduces the MCprepError class, which aims to give error messages enough information one needs to debug. With MCprepError, the following can be used as general rules:
The function that returns an object is responsible for providing the following:
Error type
File and line number (this is where the inspect module comes in handy)
Error message (optional, as some functions might be general purpose)
The function that receives the error is responsible for the following:
Graceful handling of the error
Alerting the user of the error, with all the information provided by the error object
To bring this out to devs, this PR doesn't perform any actual migration of old code, hence why it's pretty lackluster. The goal is to migrate as we go.
In the past, MCprep used many methods to determine if an error occurred somewhere outside an operator, such as checking for
None
, using1
to signify an exception, etc. These methods have the following issues though:To mitigate these issues in new code, a new error class is needed. This PR introduces the
MCprepError
class, which aims to give error messages enough information one needs to debug. WithMCprepError
, the following can be used as general rules:inspect
module comes in handy)To bring this out to devs, this PR doesn't perform any actual migration of old code, hence why it's pretty lackluster. The goal is to migrate as we go.