Skip to content

[Feat] More specific Exception statements - #287

Merged
fjosw merged 2 commits into
developfrom
more_specific_exceptions
Jul 6, 2026
Merged

[Feat] More specific Exception statements#287
fjosw merged 2 commits into
developfrom
more_specific_exceptions

Conversation

@fjosw

@fjosw fjosw commented Jul 6, 2026

Copy link
Copy Markdown
Owner

No description provided.

@fjosw
fjosw requested review from Copilot and removed request for jkuhl-uni and s-kuberski July 6, 2026 09:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Exception with ValueError, TypeError, FileNotFoundError, and NotImplementedError in 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.

Comment thread pyerrors/mpm.py Outdated
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)
Comment thread pyerrors/input/dobs.py Outdated
return '\n'
else:
raise Exception('Type', type(d[k]), 'not supported in export!')
raise TypeError('Type', type(d[k]), 'not supported in export!')
Comment thread pyerrors/input/dobs.py Outdated
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!')
Comment thread pyerrors/input/dobs.py Outdated
return '\n'
else:
raise Exception('Type', type(d[k]), 'not supported in export!')
raise TypeError('Type', type(d[k]), 'not supported in export!')
Comment thread pyerrors/input/dobs.py Outdated
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!')
Comment thread pyerrors/input/dobs.py Outdated
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))
Comment thread pyerrors/input/dobs.py Outdated
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))
Comment thread pyerrors/input/dobs.py Outdated
Comment thread pyerrors/input/dobs.py Outdated
Comment thread pyerrors/input/openQCD.py Outdated

@s-kuberski s-kuberski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for continuing to clean up the code. This looks good!

@fjosw
fjosw merged commit 470e2c5 into develop Jul 6, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants