Skip to content

Commit

Permalink
scripts/errorlist.py: improve error list docs generation
Browse files Browse the repository at this point in the history
- also output modern rc and traceback yes/no
- recursive list of Error subclasses
  • Loading branch information
ThomasWaldmann committed Nov 9, 2023
1 parent 8eef336 commit e95a3cd
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions scripts/errorlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,38 @@

from textwrap import indent

import borg.archiver # noqa: F401 - need import to get Error and ErrorWithTraceback subclasses.
from borg.helpers import Error, ErrorWithTraceback
import borg.archiver # noqa: F401 - need import to get Error subclasses.
from borg.helpers import Error

classes = Error.__subclasses__() + ErrorWithTraceback.__subclasses__()

def subclasses(cls):
direct_subclasses = cls.__subclasses__()
return set(direct_subclasses).union([s for c in direct_subclasses for s in subclasses(c)])


# 0, 1, 2 are used for success, generic warning, generic error
# 3..127 are available for specific errors
# 128+ are reserved for signals
free_rcs = set(range(3, 128)) # 3 .. 127

# these classes map to rc 2
generic_rc_classes = set()

classes = {Error}.union(subclasses(Error))

for cls in sorted(classes, key=lambda cls: (cls.__module__, cls.__qualname__)):
if cls is ErrorWithTraceback:
continue
print(' ', cls.__qualname__)
traceback = "yes" if cls.traceback else "no"
rc = cls.exit_mcode
print(' ', cls.__qualname__, 'rc:', rc, 'traceback:', traceback)
print(indent(cls.__doc__, ' ' * 8))
if rc in free_rcs:
free_rcs.remove(rc)
elif rc == 2:
generic_rc_classes.add(cls.__qualname__)
else: # rc != 2
# if we did not intentionally map this to the generic error rc, this might be an issue:
print(f'ERROR: {rc} is not a free/available RC, but either duplicate or invalid')

print()
print('free RCs:', sorted(free_rcs))
print('generic errors:', sorted(generic_rc_classes))

0 comments on commit e95a3cd

Please sign in to comment.