Skip to content

Better error reporting/debugging for BitBucket - #816

Merged
0x2b3bfa0 merged 1 commit into
masterfrom
debug-bb-requests
Nov 19, 2021
Merged

0x2b3bfa0 merged 1 commit into
masterfrom
debug-bb-requests

Conversation

@duijf

@duijf duijf commented Nov 19, 2021

Copy link
Copy Markdown
Contributor

Continued from #813, this PR improves the logging related to BitBucket API calls.

Summary

This addresses two papercuts / UX problems:

  • Prior to this PR, there was no debug logging of the actual HTTP requests that are being made to BitBucket.
  • BitBucket sometimes does not send error responses in the documented format. This would cause subpar error messages.

Background

I tried to make CML post BitBucket comments on a commit. The API requests were failing because I did not have the "Pull requests links" application installed (this requirement is documented here)

This didn't work. CML gave me the following output:

error: Bad Request undefined

With --log debug, I also didn't get enough information about what was happening to debug the problem. I had to add the debug logging to CML directly.

The error response in this case was slightly different than what BitBucket sends normally (and what their documentation says it they send):

  • The API response was {"error": "Invalid or unknown installation"}.
  • The code assumed that BitBucket was always returning responses in the format {"error": {"message": "Some message"}}

That was causing the undefined to be printed.

The lack of context made things take a bit longer to debug than I wanted. I would have expected a request log when I passed --log debug, but it turns out we didn't have any debug logging for these requests yet. That meant I had to add the debug logging myself to get the full API response from BB.

Changes

  • Handle the undocumented error response format in addition to the format that we handled already. Fall back to an empty string, so we don't print undefined.
  • Add debug logging for requests / responses so users have more information available to inspect what's happening when things go wrong.

Let me know if we want to add tests for this or want to reorganize the code somewhat :)

@duijf
duijf requested a review from 0x2b3bfa0 November 19, 2021 11:37
@duijf
duijf temporarily deployed to internal November 19, 2021 11:37 Inactive
@duijf duijf self-assigned this Nov 19, 2021
Comment thread src/drivers/bitbucket_cloud.js Resolved
@duijf
duijf force-pushed the debug-bb-requests branch from 06080c3 to 018b915 Compare November 19, 2021 12:40
@duijf
duijf temporarily deployed to internal November 19, 2021 12:41 Inactive
@duijf
duijf requested a review from 0x2b3bfa0 November 19, 2021 12:56
Comment thread src/drivers/bitbucket_cloud.js Resolved
@duijf
duijf force-pushed the debug-bb-requests branch from 018b915 to 05c0f4a Compare November 19, 2021 15:04
@duijf
duijf temporarily deployed to internal November 19, 2021 15:04 Inactive
@duijf
duijf force-pushed the debug-bb-requests branch from 05c0f4a to 239bbeb Compare November 19, 2021 15:05
@duijf
duijf temporarily deployed to internal November 19, 2021 15:05 Inactive
@0x2b3bfa0
0x2b3bfa0 merged commit 0a674fe into master Nov 19, 2021
@0x2b3bfa0
0x2b3bfa0 deleted the debug-bb-requests branch November 19, 2021 15:27

This branch was previously deployed

1 inactive deployment
internal — 239bbebe Deployed Nov 19, 2021 by duijf
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