[Feat] More specific Exception statements - #287
Merged
Conversation
fjosw
requested review from
Copilot
and removed request for
jkuhl-uni and
s-kuberski
July 6, 2026 09:18
There was a problem hiding this comment.
Pull request overview
This PR improves error signaling across pyerrors by replacing broad Exception raises with more specific built-in exception types, making failures easier to interpret and to catch programmatically.
Changes:
- Replace generic
ExceptionwithValueError,TypeError,FileNotFoundError, andNotImplementedErrorin input validation and unsupported-feature branches. - Align error types across core modules (observables, correlators, linear algebra) and multiple input backends/export utilities.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| pyerrors/obs.py | Uses NotImplementedError for unsupported numerical-derivative multi mode. |
| pyerrors/mpm.py | Switches dataset/pencil validation failures to ValueError. |
| pyerrors/misc.py | Uses ValueError/TypeError for invalid autocorrelation bounds and mixed-type Obs lists. |
| pyerrors/linalg.py | Uses NotImplementedError for unsupported Cholesky on CObs. |
| pyerrors/input/utils.py | Uses FileNotFoundError when expected directories are missing. |
| pyerrors/input/sfcf.py | Uses ValueError/FileNotFoundError for invalid versions, missing directories/replicas, and invalid naming/config checks. |
| pyerrors/input/openQCD.py | Uses ValueError/TypeError/NotImplementedError/FileNotFoundError for invalid versions/args and unsupported norms/flows. |
| pyerrors/input/misc.py | Uses FileNotFoundError/ValueError for missing directories and replica start/stop mismatches. |
| pyerrors/input/json.py | Uses ValueError/TypeError for invalid placeholder/export inputs. |
| pyerrors/input/hadrons.py | Uses FileNotFoundError for missing input files and NotImplementedError for unsupported file contents. |
| pyerrors/input/dobs.py | Uses TypeError/ValueError for export/import argument validation and unsupported types. |
| pyerrors/fits.py | Uses ValueError for invalid initial-guess length. |
| pyerrors/covobs.py | Uses ValueError for invalid covariance/grad shapes and covariance properties. |
| pyerrors/correlators.py | Uses ValueError/TypeError for invalid correlator dimensionality, partner type, parity, and missing plateau range. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| raise ValueError('The pencil p has to be smaller than the number of data samples.') | ||
| if p < k or n_data - p < k: | ||
| raise Exception('Cannot extract', k, 'energy levels with p=', p, 'and N-p=', n_data - p) | ||
| raise ValueError('Cannot extract', k, 'energy levels with p=', p, 'and N-p=', n_data - p) |
| return '\n' | ||
| else: | ||
| raise Exception('Type', type(d[k]), 'not supported in export!') | ||
| raise TypeError('Type', type(d[k]), 'not supported in export!') |
| raise TypeError('Type', type(d[k]), 'not supported in export!') | ||
| else: | ||
| raise Exception('Type', type(d), 'not supported in export!') | ||
| raise TypeError('Type', type(d), 'not supported in export!') |
| return '\n' | ||
| else: | ||
| raise Exception('Type', type(d[k]), 'not supported in export!') | ||
| raise TypeError('Type', type(d[k]), 'not supported in export!') |
| raise TypeError('Type', type(d[k]), 'not supported in export!') | ||
| else: | ||
| raise Exception('Type', type(d), 'not supported in export!') | ||
| raise TypeError('Type', type(d), 'not supported in export!') |
| name = name.replace(separator_insertion, f"|{separator_insertion}") | ||
| else: | ||
| raise Exception("separator_insertion has to be string or int, is ", type(separator_insertion)) | ||
| raise TypeError("separator_insertion has to be string or int, is ", type(separator_insertion)) |
| rname = rname.replace(separator_insertion, f"|{separator_insertion}") | ||
| else: | ||
| raise Exception("separator_insertion has to be string or int, is ", type(separator_insertion)) | ||
| raise TypeError("separator_insertion has to be string or int, is ", type(separator_insertion)) |
s-kuberski
approved these changes
Jul 6, 2026
s-kuberski
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for continuing to clean up the code. This looks good!
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.
No description provided.