Skip to content

Commit

Permalink
Avoid raising raw 'Exception' (#103)
Browse files Browse the repository at this point in the history
* Avoid raising raw 'Exception'.

* Run isort.

* Adjust error type.
  • Loading branch information
felixfontein authored Mar 10, 2023
1 parent 3aa0db8 commit 52288a4
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 9 deletions.
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

0 comments on commit 52288a4

Please sign in to comment.