Skip to content

Fix/handle invalid known parser #1180

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
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
10 changes: 7 additions & 3 deletions src/semantic_release/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from semantic_release import globals
from semantic_release.cli.commands.main import main as cli_main
from semantic_release.enums import SemanticReleaseLogLevels


def main() -> None:
Expand All @@ -18,7 +19,7 @@ def main() -> None:
print("\n-- User Abort! --", file=sys.stderr)
sys.exit(127)
except Exception as err: # noqa: BLE001, graceful error handling across application
if globals.debug:
if globals.log_level <= SemanticReleaseLogLevels.DEBUG:
print(f"{err.__class__.__name__}: {err}\n", file=sys.stderr)
etype, value, traceback = sys.exc_info()
print(
Expand All @@ -35,9 +36,12 @@ def main() -> None:
file=sys.stderr,
)

print(f"::ERROR:: {err}", file=sys.stderr)
print(
str.join("\n", [f"::ERROR:: {line}" for line in str(err).splitlines()]),
file=sys.stderr,
)

if not globals.debug:
if globals.log_level > SemanticReleaseLogLevels.DEBUG:
print(
"Run semantic-release in very verbose mode (-vv) to see the full traceback.",
file=sys.stderr,
Expand Down
9 changes: 3 additions & 6 deletions src/semantic_release/cli/commands/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ def main(
SemanticReleaseLogLevels.SILLY,
]

log_level = log_levels[verbosity]
globals.log_level = log_levels[verbosity]

logging.basicConfig(
level=log_level,
level=globals.log_level,
format=FORMAT,
datefmt="[%X]",
handlers=[
Expand All @@ -130,10 +130,7 @@ def main(
)

logger = logging.getLogger(__name__)
logger.debug("logging level set to: %s", logging.getLevelName(log_level))

if log_level <= logging.DEBUG:
globals.debug = True
logger.debug("logging level set to: %s", logging.getLevelName(globals.log_level))

if noop:
rprint(
Expand Down
11 changes: 11 additions & 0 deletions src/semantic_release/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,17 @@ def from_raw_config( # noqa: C901
if raw.commit_parser in _known_commit_parsers
else dynamic_import(raw.commit_parser)
)
except ValueError as err:
raise ParserLoadError(
str.join(
"\n",
[
f"Unrecognized commit parser value: {raw.commit_parser!r}.",
str(err),
"Unable to load the given parser! Check your configuration!",
],
)
) from err
except ModuleNotFoundError as err:
raise ParserLoadError(
str.join(
Expand Down
6 changes: 4 additions & 2 deletions src/semantic_release/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

from __future__ import annotations

debug: bool = False
"""bool: Enable debug level logging and runtime actions."""
from semantic_release.enums import SemanticReleaseLogLevels

log_level: SemanticReleaseLogLevels = SemanticReleaseLogLevels.WARNING
"""int: Logging level for semantic-release"""
6 changes: 6 additions & 0 deletions src/semantic_release/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ def dynamic_import(import_path: str) -> Any:
Dynamically import an object from a conventionally formatted "module:attribute"
string
"""
if ":" not in import_path:
raise ValueError(
f"Invalid import path {import_path!r}, must use 'module:Class' format"
)

# Split the import path into module and attribute
module_name, attr = import_path.split(":", maxsplit=1)

# Check if the module is a file path, if it can be resolved and exists on disk then import as a file
Expand Down
Loading