mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 22:40:09 +01:00
better error reporting
This commit is contained in:
parent
e85485e084
commit
863bc956c7
4 changed files with 25 additions and 7 deletions
|
|
@ -224,7 +224,11 @@ def _bump(cfg: config.Config, new_version: str, allow_dirty: bool = False) -> No
|
|||
if _vcs:
|
||||
_assert_not_dirty(_vcs, filepaths, allow_dirty)
|
||||
|
||||
rewrite.rewrite(new_version, cfg.file_patterns)
|
||||
try:
|
||||
rewrite.rewrite(new_version, cfg.file_patterns)
|
||||
except ValueError as ex:
|
||||
log.error(str(ex))
|
||||
sys.exit(1)
|
||||
|
||||
if _vcs is None or not cfg.commit:
|
||||
return
|
||||
|
|
@ -314,7 +318,11 @@ def bump(
|
|||
log.info(f"New Version: {new_version}")
|
||||
|
||||
if dry or verbose >= 2:
|
||||
print(rewrite.diff(new_version, cfg.file_patterns))
|
||||
try:
|
||||
print(rewrite.diff(new_version, cfg.file_patterns))
|
||||
except ValueError as ex:
|
||||
log.error(str(ex))
|
||||
sys.exit(1)
|
||||
|
||||
if dry:
|
||||
return
|
||||
|
|
|
|||
|
|
@ -94,7 +94,11 @@ def _iter_file_paths(
|
|||
file_patterns: config.PatternsByGlob
|
||||
) -> typ.Iterable[typ.Tuple[pl.Path, config.Patterns]]:
|
||||
for globstr, patterns in file_patterns.items():
|
||||
for file_path_str in glob.glob(globstr):
|
||||
file_paths = glob.glob(globstr)
|
||||
if not any(file_paths):
|
||||
errmsg = f"No files found for path/glob '{globstr}'"
|
||||
raise ValueError(errmsg)
|
||||
for file_path_str in file_paths:
|
||||
file_path = pl.Path(file_path_str)
|
||||
yield (file_path, patterns)
|
||||
|
||||
|
|
@ -171,7 +175,12 @@ def diff(new_version: str, file_patterns: config.PatternsByGlob) -> str:
|
|||
|
||||
rfd = rfd_from_content(patterns, new_version, content)
|
||||
rfd = rfd._replace(path=str(file_path))
|
||||
full_diff += "\n".join(diff_lines(rfd)) + "\n"
|
||||
lines = diff_lines(rfd)
|
||||
if len(lines) == 0:
|
||||
errmsg = f"No patterns matched for '{file_path}'"
|
||||
raise ValueError(errmsg)
|
||||
|
||||
full_diff += "\n".join(lines) + "\n"
|
||||
|
||||
full_diff = full_diff.rstrip("\n")
|
||||
return full_diff
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue