Skip to content

refactor: use custom exception for error handling #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 14, 2020
Merged

Conversation

Lee-W
Copy link
Member

@Lee-W Lee-W commented Jun 5, 2020

the error code used is embedded into these exceptions

(Thanks for sending a pull request! Please fill in the following content to let us know better about this change.)

Types of changes

Please put an x in the box that applies

  • Refactoring
  • Documentation Update

Description

  • use custom exception for error handling
  • do not show traceback if the raised exception is CommitizenException
  • introduce DryRunExit, ExpectedExit, NoCommandFoundError, InvalidCommandArgumentError (Remove all the SystemExit)
  • remove unused NO_COMMIT_MSG error code

TODO

  • Handle print message
  • Add documentation about how to use error code
  • Group CommitizenException (e.g. git group, command line group and etc.)

Checklist:

  • Add test cases to all the changes you introduce
  • Run ./script/lint and ./script/test locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Steps to Test This Pull Request

Try to execute the commands that will raise exceptions. e.g., cz bump --dry-run

Expected behavior

No behavior should change after this change

Related Issue

#128

Additional context

Add any other context or screenshots about the pull request here.

@Lee-W Lee-W force-pushed the refactor-error-code branch from b5b0709 to 8a51843 Compare June 5, 2020 16:04
@codecov
Copy link

codecov bot commented Jun 5, 2020

Codecov Report

Merging #201 into master will increase coverage by 3.49%.
The diff coverage is 92.59%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #201      +/-   ##
==========================================
+ Coverage   92.14%   95.64%   +3.49%     
==========================================
  Files          35       34       -1     
  Lines         968      942      -26     
==========================================
+ Hits          892      901       +9     
+ Misses         76       41      -35     
Flag Coverage Δ
#unittests 95.64% <92.59%> (+3.49%) ⬆️
Impacted Files Coverage Δ
commitizen/commands/changelog.py 97.22% <83.33%> (+5.33%) ⬆️
commitizen/commands/bump.py 91.46% <87.50%> (+2.95%) ⬆️
commitizen/cli.py 93.33% <88.88%> (+2.15%) ⬆️
commitizen/commands/check.py 100.00% <100.00%> (ø)
commitizen/commands/commit.py 96.49% <100.00%> (+3.15%) ⬆️
commitizen/commands/init.py 88.88% <100.00%> (+14.64%) ⬆️
commitizen/config/__init__.py 97.67% <100.00%> (+15.85%) ⬆️
commitizen/cz/customize/customize.py 93.33% <100.00%> (+8.55%) ⬆️
commitizen/factory.py 100.00% <100.00%> (ø)
commitizen/cz/base.py 100.00% <0.00%> (+3.22%) ⬆️
... and 4 more

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 a108872...32287f0. Read the comment docs.

…validCommandArgumentError

Instead of using SystemExit, we raise these error as CommitizenException
@Lee-W
Copy link
Member Author

Lee-W commented Jun 5, 2020

@woile I've finished the major part of this refactoring. Could you please take a look at it? 🙂 I'm still working on the error message part. I'll also add documentation for these error codes.

@Lee-W Lee-W force-pushed the refactor-error-code branch from 06ad77c to 68b7d69 Compare June 6, 2020 07:41
@Lee-W Lee-W force-pushed the refactor-error-code branch 2 times, most recently from 3fc7d3a to 69ce10c Compare June 14, 2020 10:33
@Lee-W Lee-W marked this pull request as ready for review June 14, 2020 10:42
@Lee-W Lee-W force-pushed the refactor-error-code branch from 69ce10c to fb888fe Compare June 14, 2020 11:08
@Lee-W Lee-W force-pushed the refactor-error-code branch from fb888fe to 4a1b89b Compare June 14, 2020 11:12
@Lee-W Lee-W force-pushed the refactor-error-code branch from 04a65c8 to 5dfdeeb Compare June 14, 2020 13:45
@Lee-W Lee-W requested a review from woile June 14, 2020 14:30
@Lee-W
Copy link
Member Author

Lee-W commented Jun 14, 2020

@woile This pr is finally ready for reviewing 🎉

@Lee-W Lee-W merged commit cbe8f11 into master Jun 14, 2020
@Lee-W Lee-W deleted the refactor-error-code branch June 24, 2020 08:07
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.

2 participants