Cz-cli: Don't throw the error when git-cz fails

Created on 15 May 2017  ·  12Comments  ·  Source: commitizen/cz-cli

Right now when the command fails, it prints the whole stack trace. Is it really necessary?

question

Most helpful comment

@jimthedev,

Thanks for explanation and calm, had not seen the explanation above, sorry for this. I will consider creating PR soon enough.

keep up the good work! =]

All 12 comments

I'm open to hearing arguments or PRs to improve this functionality. Currently we give you everything because a git hook including test output may have failed and we want you to see which tests failed.

It adds a lot of noise and is not very informative. See:

Trying to git cz with empty index:

.../node_modules/commitizen/dist/cli/strategies/git-cz.js:87
      throw new Error('No files added to staging! Did you forget to run git add?');
      ^

Error: No files added to staging! Did you forget to run git add?
    at .../node_modules/commitizen/dist/cli/strategies/git-cz.js:87:13
    at .../node_modules/commitizen/dist/commitizen/staging.js:25:5
    at ChildProcess.exithandler (child_process.js:197:7)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:194:7)
    at maybeClose (internal/child_process.js:899:16)
    at Socket.<anonymous> (internal/child_process.js:342:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at Pipe._handle.close [as _onclose] (net.js:511:12)

Combined with a commit-msg hook:

nps executing: conventional-changelog-lint -e
⧗   input: feat: foo.
✖   message may not end with full stop [subject-full-stop]
✖   found 1 problems, 0 warnings
The script called "lint.commit" which runs "conventional-changelog-lint -e" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.1.0/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code

> husky - commit-msg hook failed (add --no-verify to bypass)
> husky - to debug, use 'npm run commitmsg'
.../node_modules/commitizen/dist/cli/strategies/git-cz.js:102
        throw error;
        ^

Error: git exited with error code 1
    at ChildProcess.<anonymous> (.../node_modules/commitizen/dist/git/commit.js:50:26)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:194:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)

All these errors should be handled IMO and turned into non-zero exit with just the error message printed.

Fair enough. Would you be interested in putting in a PR?

--
Jim ForCy

On May 15, 2017 at 8:03:07 AM, Łukasz Moroz ([email protected])
wrote:

It adds a lot of noise and is not very informative. See:

Trying to git cz with empty index:

.../node_modules/commitizen/dist/cli/strategies/git-cz.js:87
throw new Error('No files added to staging! Did you forget to run git add?');
^

Error: No files added to staging! Did you forget to run git add?
at .../node_modules/commitizen/dist/cli/strategies/git-cz.js:87:13
at .../node_modules/commitizen/dist/commitizen/staging.js:25:5
at ChildProcess.exithandler (child_process.js:197:7)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:194:7)
at maybeClose (internal/child_process.js:899:16)
at Socket. (internal/child_process.js:342:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:191:7)
at Pipe._handle.close [as _onclose] (net.js:511:12)

Combined with a commit-msg hook:

nps executing: conventional-changelog-lint -e
⧗ input: feat: foo.
✖ message may not end with full stop [subject-full-stop]
✖ found 1 problems, 0 warnings
The script called "lint.commit" which runs "conventional-changelog-lint -e" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.1.0/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code

husky - commit-msg hook failed (add --no-verify to bypass)
husky - to debug, use 'npm run commitmsg'
.../node_modules/commitizen/dist/cli/strategies/git-cz.js:102
throw error;
^

Error: git exited with error code 1
at ChildProcess. (.../node_modules/commitizen/dist/git/commit.js:50:26)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:194:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)

All these errors should be handled IMO and turned into non-zero exit with
just the error message printed.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/commitizen/cz-cli/issues/436#issuecomment-301468194,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGpijy6GMBFsHSfNLLkK8i0yCxBqpwqks5r6E0LgaJpZM4Navxs
.

Sure

[email protected] this is still in right?

/usr/local/lib/node_modules/commitizen/dist/cli/strategies/git-cz.js:87
      throw new Error('No files added to staging! Did you forget to run git add?');
      ^

Error: No files added to staging! Did you forget to run git add?
    at /usr/local/lib/node_modules/commitizen/dist/cli/strategies/git-cz.js:87:13
    at /usr/local/lib/node_modules/commitizen/dist/commitizen/staging.js:25:5
    at ChildProcess.exithandler (child_process.js:267:7)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Socket.stream.socket.on (internal/child_process.js:346:11)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at Pipe._handle.close [as _onclose] (net.js:554:12)

@bm-stschneider don.t think so. This was merged by never published? /cc @jimthedev

[email protected]

/usr/local/lib/node_modules/commitizen/dist/cli/strategies/git-cz.js:87
      throw new Error('No files added to staging! Did you forget to run git add?');
      ^

Error: No files added to staging! Did you forget to run git add?
    at /usr/local/lib/node_modules/commitizen/dist/cli/strategies/git-cz.js:87:13
    at /usr/local/lib/node_modules/commitizen/dist/commitizen/staging.js:25:5
    at ChildProcess.exithandler (child_process.js:264:7)
    at ChildProcess.emit (events.js:160:13)
    at maybeClose (internal/child_process.js:943:16)
    at Socket.stream.socket.on (internal/child_process.js:363:11)
    at Socket.emit (events.js:160:13)
    at Pipe._handle.close [as _onclose] (net.js:562:12)

@bm-stschneider, @raisedadead and @jimthedev.

Is this right?

Did you run got add myfile.md first?

On February 17, 2018 at 9:05:26 AM, Vinícius Carvalho (
[email protected]) wrote:

[email protected]

/usr/local/lib/node_modules/commitizen/dist/cli/strategies/git-cz.js:87
throw new Error('No files added to staging! Did you forget to run git add?');
^

Error: No files added to staging! Did you forget to run git add?
at /usr/local/lib/node_modules/commitizen/dist/cli/strategies/git-cz.js:87:13
at /usr/local/lib/node_modules/commitizen/dist/commitizen/staging.js:25:5
at ChildProcess.exithandler (child_process.js:264:7)
at ChildProcess.emit (events.js:160:13)
at maybeClose (internal/child_process.js:943:16)
at Socket.stream.socket.on (internal/child_process.js:363:11)
at Socket.emit (events.js:160:13)
at Pipe._handle.close [as _onclose] (net.js:562:12)

@bm-stschneider https://github.com/bm-stschneider, @raisedadead
https://github.com/raisedadead and @jimthedev
https://github.com/jimthedev.

Is this right?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/commitizen/cz-cli/issues/436#issuecomment-366447116,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGpijDkNQ5ZNkr-0VZiLrTu9YaA6UaRks5tVuq2gaJpZM4Navxs
.

No, you would replace that with your file that you want to commit. Or you
could use git add . for all changed files.

--
Jim ForCy

On February 17, 2018 at 10:06:05 AM, Vinícius Carvalho (
[email protected]) wrote:

Sorry but I do not know this file, where could I find it?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/commitizen/cz-cli/issues/436#issuecomment-366451006,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGpio0e22A2yzE6xW7FRo0l7QB-3vhNks5tVvjtgaJpZM4Navxs
.

Sorry but I do not know this file, where could I find it?
If you're talking about adding the file in the git stage, myfile.md being a file from my project, that's not what I'm talking about.
My question has to do with why the exit is not treated to show a more friendly and easy-to-understand message

Please see https://github.com/commitizen/cz-cli/issues/436#issuecomment-301452208 which explains that we are open to a PR for better functionality but at the moment we give everything since it is helpful when running in a git hook scenario. I will point out that Error: No files added to staging! Did you forget to run git add? is right there. How would you prefer the message to be written? Please offer suggestions.

@jimthedev,

Thanks for explanation and calm, had not seen the explanation above, sorry for this. I will consider creating PR soon enough.

keep up the good work! =]

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaylaw81 picture jaylaw81  ·  6Comments

brandondurham picture brandondurham  ·  7Comments

micky2be picture micky2be  ·  6Comments

lwouis picture lwouis  ·  4Comments

fendy-g picture fendy-g  ·  7Comments