Skip to content

Clean no config exit#302

Merged
altendky merged 9 commits intotwisted:masterfrom
altendky:clean_no_config_exit
Dec 19, 2020
Merged

Clean no config exit#302
altendky merged 9 commits intotwisted:masterfrom
altendky:clean_no_config_exit

Conversation

@altendky
Copy link
Copy Markdown
Member

Fixes #84.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Dec 16, 2020

Codecov Report

Merging #302 (7376bca) into master (06f94d5) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #302      +/-   ##
==========================================
+ Coverage   95.37%   95.39%   +0.02%     
==========================================
  Files          20       20              
  Lines        1038     1043       +5     
  Branches      104      103       -1     
==========================================
+ Hits          990      995       +5     
  Misses         27       27              
  Partials       21       21              
Impacted Files Coverage Δ
src/towncrier/build.py 89.61% <100.00%> (-0.39%) ⬇️
src/towncrier/test/test_build.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 06f94d5...7376bca. Read the comment docs.

Copy link
Copy Markdown
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good. Only minor comments.

Please consider printing the config error to stderr (and any otther error message).

But I think that this can be fixed and then merged without any review.

else:
traceback.print_exc(file=sys.stderr)
raise
raise
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the ConfigError should also be sent to stderr... as it is still an error. Just that is an error that doesn't require a traceback.

Maybe use this to always exit (raise SystemExit) in _main ... but maybe your fix work better with Click.... so is ok.

    if isinstance(e, ConfigError):
        print(e, file=sys.stderr)
    else:
        traceback.print_exc(file=sys.stderr)
    sys.exit(1)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems I forgot to go back and convert this to except ConfigError as e:... But, to your comments, sure, I'll put the error on stderr. For the traceback, I figured that an uncaught exception ends up on stderr anyways. That was the idea with the bare raise (or after adjusting to except ConfigError, nothing) Though, the explicit sys.exit(1) does make the exit code more... explicit. I don't know if that's good for unexpected exceptions or not.

As to Click, it does offer its own version of this mechanism. I started to switch to that briefly before seeing that this was already here. I figured I would leave this focused and consider a full application switch over to Click exceptions separately (if at all). So, I don't think Click needs to be significantly included in consideration how this should be written.

Comment on lines +71 to +73
except ConfigError as e:
print(e, file=sys.stderr)
sys.exit(1)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the simplest change that 1) avoids the traceback for ConfigErrors and 2) doesn't double up the traceback on regular exceptions. Though, admittedly, 2) is actual scope creep for this PR. :] I tried your suggestion which resulted in test failures due to getting SystemExit rather than ValueError exceptions, for example. If you think that is in fact better, I can switch back and update the tests.

@adiroiban
Copy link
Copy Markdown
Member

This can be merged as it is. Thanks. It is already an improvement over the main branch.

I prefer SystemExit as for me it's an "expected error" / business as usual type of event. I don't see it as an error, it's just an instruction to end the execution ASAP :)

A ValueError is an "unexepected error" that most probably signals a bug.

But as mention, this PR can be merged. Thanks!

@altendky
Copy link
Copy Markdown
Member Author

altendky commented Dec 19, 2020

The 'expected' ConfigError is being turned into a SystemExit. The 'unexpected' ValueError in some test also got turned into SystemExit using the code you suggested. As the PR is now (about to merge), the ValueError is retained.

Well, I guess before merging I have to figure out what happened to codecov... Edit: welp, guess it fixed itself behind my back.

@altendky altendky merged commit 87860f3 into twisted:master Dec 19, 2020
@altendky altendky deleted the clean_no_config_exit branch December 19, 2020 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'NoneType' object has no attribute '__getitem__'

3 participants