restechnica / semverbot

A CLI which automates semver versioning.
Mozilla Public License 2.0
133 stars 6 forks source link

Recent git error handling improvements show unexpected log outputs (not breaking) #23

Closed shiouen closed 2 years ago

shiouen commented 2 years ago

image

These logs/prints are shown due to the git command exit status being different that 0 or the stderr containing bytes when it really shouldn't. Semverbot still works as intended but simply outputs strange logs.

The go Cobra library shows usage whenever an error occurs, even when the error is not due to faulty usage of the CLI. We can fix this with a combination of a logging implementation and using cmd.SilenceUsage = true.

shiouen commented 2 years ago

Further investigation shows that Git outputs informative messages to stderr, as the maintainers believe it is not supposed to be consumed by machines. Semverbot looks at the stderr to detect Git errors which have an exit status equal to 0, but still output to stderr.

How to reproduce:

  1. have a repo without all remote tags
  2. run sbot update version
  3. the command executes successfully and fetches all tags
  4. sbot will receive the command's output through stderr, due to Git's design
  5. sbot will detect messages on stderr, thus throwing errors after a successful command, while exit status of the command is 0

Not sure what the workaround can be here, afaik Git is not adhering to standards. Will have to investigate further.

shiouen commented 2 years ago

On closer inspection, it isn't as strange as I thought to output to stderr as described here. sbot should solely base its command error handling on the exit code instead, to fix this issue.

shiouen commented 2 years ago

Issue should be fixed by not depending on stderr to detect errors and a custom error implementation for running commands

fixed in 0.2.8