nedbat / scriv

Changelog management tool
https://scriv.readthedocs.io
Apache License 2.0
260 stars 29 forks source link

Scriv produces an obscure error when encountering an invalid Version during collection #100

Closed SnoopJ closed 1 year ago

SnoopJ commented 1 year ago

Description

With scriv==1.3.1, running collection on a changelog that includes a heading that does not contain a valid Version (as defined by scriv.util) produces a fairly obscure error.

$ scriv collect --keep --version 1.1
Collecting from changelog.d
Reading changelog CHANGELOG.md
Traceback (most recent call last):
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/bin/scriv", line 8, in <module>
    sys.exit(cli())
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/lib/python3.7/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/lib/python3.7/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/lib/python3.7/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/lib/python3.7/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/lib/python3.7/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/lib/python3.7/site-packages/scriv/collect.py", line 74, in collect
    if eversion == version:
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/lib/python3.7/site-packages/scriv/util.py", line 96, in __eq__
    return this.lstrip("v") == that.lstrip("v")
AttributeError: 'NoneType' object has no attribute 'lstrip'

The error is slightly less obscure against main (58fae87), but still confusing:

$ scriv collect --keep --version 1.1
Collecting from changelog.d
Reading changelog CHANGELOG.md
Traceback (most recent call last):
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/bin/scriv", line 11, in <module>
    load_entry_point('scriv', 'console_scripts', 'scriv')()
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/lib/python3.7/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/lib/python3.7/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/lib/python3.7/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/lib/python3.7/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/snoopjedi/repos/scriv-src/.direnv/python-3.7.16/lib/python3.7/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/snoopjedi/repos/scriv-src/src/scriv/collect.py", line 74, in collect
    if eversion == version:
  File "/home/snoopjedi/repos/scriv-src/src/scriv/util.py", line 91, in __eq__
    assert isinstance(other, Version)
AssertionError

The problem here is the Older versions heading in the CHANGELOG.md, adding <!-- scriv-end-here --> above this heading avoids the issue, but it would be nice if scriv gave a more explicit report about what went wrong in this case.

Reproduction

These files should be all that is needed to reproduce the above errors.

# pyproject.toml
[tool.scriv]
format = "md"
<!-- CHANGELOG. md -->
<a id="changelog-1.0"></a>
# 1.0

### Added

- Blah blah blah

# Older versions

<a id="changelog-0.9"></a>
# 0.9

### Added

- Blah blah blah
<!-- changelog.d/20230717_112025_snoopjedi.md -->
### Added

- Some amazing new feature

Notes

I discovered this on Python 3.7 but I believe it applies to all supported versions.

nedbat commented 1 year ago

This is now released as part of scriv 1.4.0.