Repository navigation
Conversation
mgovers
force-pushed
the
pgm/feature/fine-grained-base-error-types
branch
from
November 13, 2026 12:16
efe2751 to
0ca6ad4
Compare
Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
mgovers
force-pushed
the
pgm/feature/fine-grained-base-error-types
branch
from
November 13, 2026 12:29
0ca6ad4 to
4cfb787
Compare
This was referenced Nov 13, 2026
Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
mgovers
force-pushed
the
pgm/feature/fine-grained-base-error-types
branch
from
November 13, 2026 13:05
e57de7d to
af331d7
Compare
Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
Member
Author
|
do-not-merge label added pending some internal discussion |
Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
|
Member
Author
|
@WinApiMan, Will this change affect you, and if so, in what way? |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Part of #509
Cherry-picked from #1635
What is new
This PR replaces many instances in which the generic catch-all
PGM_regular_errorerror code was reported, with the following new, more fine-grained error codes that represent error categories.In #1635, additional subtypes will be added that are (modulo 256) the same as this type, i.e.
(derived - base) % 256 == 0ifderivedis a subtype ofbaseand0 < base < 256and0 < derived.This change therefore enables more fine-grained control of error handling mechanisms. Of course, it is important to note that it is not good to depend too much on that for stability reasons, but it is nice to have options, rather than to depend on only error messages.
Rationale
Why we are doing this change
Errors are sometimes difficult to decode.
PGM_regular_erroris not very descriptive and up til now, one had to rely on string decoding or regex pattern matching. While that works to some extend, this is not really sustainable and even less stable (e.g. correcting a typo may break the pattern matching). In PGM, the Python API, in particular, suffers from this issue. #509 has been open in this regard for a long time.Why we do not consider this change breaking
We consider the precise error being reported to be intentionally undefined behavior, particularly of the unspecified behavior class. A user is only affected if their program strongly depends on the precise error type and therefore depends on undefined behavior.
What we took into consideration
PGM_regular_erroralready suggests that there may be other error types and that types may change in the future.PGM_regular_errororPGM_batch_error, depending on the type of issue encountered.Which users are affected?
Users may be affected if they use a pattern like the example below.
Users that only depend on
PGM_no_errorare not affected.PGM_no_erroris, and will remain, an invariant of PGM.Weakly affected users (users with good fall-back mechanisms)
If
handle_other_errorsis simply a fall-back to report nicely the encountered error, then the user can benefit from the alternatives below, but the change for sure is not breaking to them.Strongly affected users (users that invoke undefined behavior)
If
handle_other_errorsis a strong fallback mechanism, e.g. callsabort()when an unknown error is encountered, then the user strongly depends on undefined behavior and this change will affect them. Since it concerns undefined behavior, this is the user's responsibility to resolve this.Alternatives
Instead of hard matching, users can use 2 options that we foresee stable going forward.
Option 1: use
PGM_error_code_is_subcode_of(error_code, base_error_code)This is guaranteed to be stable and future-proof, even as we add more error types and levels. However, exhaustive listing is mostly recommended in case the total amount of
Option 2: use a custom modulo/bit-masking approach
We intend to keep error codes stable
modulo 256, i.e., we are adopting a multi-level error code schema, in which every level has 8 bits. In the foreseeable future, we are restricting to 4 levels, giving 32-bits of error code information, which is sufficient for most cases.PR stack structure
PGM_regular_error