power-grid-model icon indicating copy to clipboard operation
power-grid-model copied to clipboard

[FEATURE] Expose derived power grid error types

Open mgovers opened this issue 11 months ago • 0 comments

Describe the feature request

Expose all different error types thrown by the calculation core as separate error classes that derive from PowerGridError.

Rationale

Currently, all power grid errors are derived from PowerGridError. The only difference between e.g. SparseMatrixError and IterationDivergeError is the string message of the error. As a user, parsing strings (that may change in the future) is suboptimal compared to actual different errors derived from the PowerGridError.

First iteration

  • [x] Python side: done in #546 and #552
    • [x] Create separate error classes, e.g.
    class SparseMatrixError(PowerGridError):
      """Sparse matrix error class."""
      pass
    
    • [x] Look at the cpp errors which ones are necessary
    • [x] Obtain the correct error
      • [x] Short term solution: parse from the error message string
        • [x] Look through all cpp errors to make sure all error message are used.
        • [x] There may be multiple error strings for one error type
          • [x] Make sure all string combinations are parsed
        • [x] There may be cases where the same string is used for different error types
          • [x] Make sure that all error cases in cpp are handled correctly

Next step

Design

  • [ ] Python side
    • [ ] Use classes provided by the first iteration part
    • [ ] Obtain the correct error
      • [ ] Sustainable solution: raise the correct error from the C API (see below)
  • [ ] C API
    • [ ] Define other error codes for all error types defined in exceptions.hpp
    • [ ] Update the call_with_catch to produce the correct error code based on the raised exception.
      • [ ] Use a Lippincott pattern (see e.g. https://github.com/PowerGridModel/power-grid-model/blob/037a0e43cef1e36f49df73f177a601967ecf553b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model.hpp#L574 on usage)
  • [ ] Main Model
    • [ ] Update logic so that the correct errors are provided for each scenario batch in a batch

TBD

  • [ ] How to handle batch errors?
    • [ ] Should that be done by adding a vector with all error codes?
      • [ ] Are those error codes known by the C++ core?
    • [ ] Or should it be a vector of PowerGridErrors instead of a list of all error messages individually?
      • [ ] This requires also parsing the error code for all individual scenarios in the C API

mgovers avatar Feb 29 '24 14:02 mgovers