gaqzi / gocd-cli

A command line interface for common Go tasks
MIT License
24 stars 8 forks source link

KeyError when Triggering Pipeline #14

Open sushengloong opened 8 years ago

sushengloong commented 8 years ago

Hi,

We encountered the error below (KeyError) when running gocd-cli to trigger a pipeline. Despite the error, the pipeline was actually triggered and run successfully though the duration was close to half-an-hour. Not sure if it's gocd-cli or py-gocd or gocd server API itself that was causing the error. Any pointer?

Furthermore the API response was not written into logs so it is difficult to troubleshoot. Would you be able to suggest ways to improve logging in gocd-cli? Thanks :)

+ exec gocd pipeline trigger PIPELINE_NAME_MASKED --unlock=true --wait-until-finished=true
Traceback (most recent call last):
  File "/usr/bin/gocd", line 60, in <module>
    result = utils.get_command(server, *sys.argv[1:]).run()
  File "/usr/lib/python2.6/site-packages/gocd_cli/commands/pipeline/__init__.py", line 75, in run
    while not self._stages_finished(response):
  File "/usr/lib/python2.6/site-packages/gocd_cli/commands/pipeline/__init__.py", line 105, in _stages_finished
    if stage['result'] not in self.pipeline.final_results:
KeyError: 'result'
gaqzi commented 8 years ago

@sushengloong I've a feeling it's bad response from the server, it's not seeing stage['result'] and that would be my instinctive guess.

The code definitely should be testing that result exists before pulling in the stage, I'll have a look at it this weekend.

The suggestion for logging is great and I would suggest looking at adding logging to the request handling in gocd.Server. Default debug logging and then adding a flag for verbosity level. :)

gaqzi commented 8 years ago

I just realized, there's already a flag on gocd.Server that you can use to set the logging level for requests. It just needs to be togglable from gocd-cli.

I've a feeling that an overhaul of the flags interface is necessary to handle global flags, although a quick hack will always work for now. :P

sushengloong commented 8 years ago

Thanks! Do let me know if I can be of any help.

Regarding the flag, I tried changing Server to accept logging level via a dictionary options. A PR for your consideration - https://github.com/gaqzi/py-gocd/pull/11 :grin:

gaqzi commented 8 years ago

@sushengloong I've added code for this and manually tested it, but I still need to add some proper tests to it.

You can find it at py-gocd/feature/more-logging and gocd-cli/feature/more-logging.

sushengloong commented 8 years ago

@gaqzi nice! Looking forward to the next release.

sushengloong commented 8 years ago

@gaqzi Setting debuglevel seems to only log HTTP headers and not the request/response body. Still have to put in a few print statements for that.

What we have observed is Go server API may indeed not return 'result' for the 'stage' object. As such, PR https://github.com/gaqzi/gocd-cli/pull/15 for your consideration :smiley: