-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add common exceptions module #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
95284ae
feat: Add common exceptions module
AlejandroFernandezLuces 9295d7c
fix: Add EOL
AlejandroFernandezLuces 2109a59
Merge branch 'main' into feat/add-common-exceptions
AlejandroFernandezLuces 634b4a3
fix: pre-commit
AlejandroFernandezLuces c5e1bc7
fix: Missing docs
AlejandroFernandezLuces 1a4c306
Update src/ansys/tools/exceptions.py
AlejandroFernandezLuces a134e0d
fix: Admit type, make params mandatory
AlejandroFernandezLuces 581a74a
fix: pre-commit
AlejandroFernandezLuces 96d1e2b
Update src/ansys/tools/exceptions.py
AlejandroFernandezLuces 81f23b0
Update src/ansys/tools/exceptions.py
AlejandroFernandezLuces File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| # of this software and associated documentation files (the "Software"), to deal | ||
| # in the Software without restriction, including without limitation the rights | ||
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| # copies of the Software, and to permit persons to whom the Software is | ||
| # furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in all | ||
| # copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| # SOFTWARE. | ||
| """Exceptions module.""" | ||
|
|
||
|
|
||
| class AnsysError(Exception): | ||
| """Base class for all exceptions raised by the Ansys API. | ||
|
|
||
| Can be used to catch all Ansys-related exceptions. | ||
| """ | ||
|
|
||
| def __init__(self, message: str) -> None: | ||
| """Initialize the exception with a message.""" | ||
| super().__init__(message) | ||
| self.message = message | ||
|
|
||
|
|
||
| class AnsysTypeError(AnsysError): | ||
| """Error raised when an argument is of the wrong type. | ||
|
|
||
| Exception raised when python wise types would work, but internal | ||
| Ansys specific typing is not right. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| expected_type : str | type | ||
| The expected type of the argument. | ||
| actual_type : str | type | ||
| The actual type of the argument. | ||
| """ | ||
|
|
||
| def __init__(self, expected_type: str | type, actual_type: str | type = None) -> None: | ||
| """Initialize the exception with expected and actual types.""" | ||
| expected_type = expected_type if isinstance(expected_type, str) else expected_type.__name__ | ||
| actual_type= actual_type if isinstance(actual_type, str) else actual_type.__name__ | ||
| message = f"Expected type {expected_type}, but got {actual_type}." | ||
| super().__init__(message) | ||
| self.expected_type = expected_type | ||
| self.actual_type = actual_type | ||
|
|
||
| class AnsysLogicError(AnsysError): | ||
| """Exception raised when an unexpected logical condition occurs. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| message : str | ||
| The error message. | ||
| """ | ||
|
|
||
| def __init__(self, message: str) -> None: | ||
| """Initialize the exception with a message.""" | ||
| super().__init__(message) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.