rtts / djhtml

Django/Jinja template indenter
GNU General Public License v3.0
572 stars 32 forks source link

Incorrect exit status when there are 256 (or more) problematic files #70

Closed JaapJoris closed 1 year ago

JaapJoris commented 1 year ago

The README states the following:

If any errors were encountered, the exit status indicate[s] the number of problematic files. However, when the option -c / --check is used, the exit status is the number of files that would have changed, but no changes are actually made.

The actual statement responsible for this can be found here:

sys.exit(changed_files if args.check else problematic_files)

While this seems clever, it's actually an antipattern because, in POSIX, the exit status cannot be greater than 255. When the number of problematic files is 256, the exit status will wrap around and actually become 0 again, indicating success rather than failure. This is particularly nasty for scripts that check exit status, because once in blue moon they will function incorrectly and most likely leave their authors puzzled as to why.

To fix it, let's make the exit status always 1 or 0 and nothing else.