Skip to content
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

Avoid raising raw 'Exception' #103

Merged
merged 3 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/103-exceptions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "Use more specific exceptions than ``Exception`` for some cases in internal code (https://github.com/ansible-community/antsibull-changelog/pull/103)."
3 changes: 1 addition & 2 deletions src/antsibull_changelog/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@ def _get_refresh_config(args: Any,
elif part == 'fragments-without-archives':
refresh_fragments = 'without-archives'
else:
# pylint:disable-next=broad-exception-raised
raise Exception(
raise ValueError(
'The config value always_refresh contains an invalid value "{0}"'.format(
part))
return refresh_plugins, refresh_fragments
Expand Down
3 changes: 1 addition & 2 deletions src/antsibull_changelog/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ def _load_galaxy_yaml(self, needed_var: str,
if self.galaxy_yaml_loaded:
return
if not self.paths.is_collection:
# pylint:disable-next=broad-exception-raised
raise Exception('Internal error: cannot get collection details for non-collection')
raise RuntimeError('Internal error: cannot get collection details for non-collection')

if what_for is None:
what_for = 'load field "{0}"'.format(needed_var)
Expand Down
3 changes: 1 addition & 2 deletions src/antsibull_changelog/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,7 @@ def _get_ansible_core_version(paths: PathsConfig) -> packaging.version.Version:
match = re.match(regex, output)
if match:
return packaging.version.Version(match.group(1))
# pylint:disable-next=broad-exception-raised
raise Exception(
raise RuntimeError(
f'Cannot extract ansible-core version from ansible-doc --version output:\n{output}')


Expand Down
3 changes: 1 addition & 2 deletions src/antsibull_changelog/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ def load_toml(path: str) -> Any:
if HAS_TOML:
with open(path, 'r', encoding='utf-8') as f:
return toml.loads(f.read())
# pylint:disable-next=broad-exception-raised
raise Exception('Need tomllib/tomli/toml library to read TOML file')
raise RuntimeError('Need tomllib/tomli/toml library to read TOML file')
1 change: 0 additions & 1 deletion tests/functional/test_changelog_basic_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import os

import mock

from fixtures import other_changelog # noqa: F401; pylint: disable=unused-variable
from fixtures import create_plugin

Expand Down