Skip to content
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

bitbucket has started giving 400 Bad Request (but still succeeds) #1285

Open
wizardishungry opened this issue Sep 15, 2022 · 7 comments
Open

Comments

@wizardishungry
Copy link

wizardishungry commented Sep 15, 2022

In a fairly new installation of v0.14.1 that was working for a few days, we have started seeing consistent errors from reviewdog (for several days), but the code insights are still updated in bitbucket.

go run github.com/reviewdog/reviewdog/cmd/reviewdog/... -diff="git diff master" -reporter=bitbucket-code-report -filter-mode nofilter
2022/09/15 14:51:09 reviewdog: [start]	runner=golangci-lint
2022/09/15 14:52:34 reviewdog: [finish]	runner=golangci-lint	error=exit status 1
reviewdog: failed to post annotations: failed to create code insights annotations: bitbucket Cloud API error: 400 Bad Request
exit status 1
@pararang
Copy link

pararang commented Oct 5, 2022

Hi @wizardishungry , did you find out the solution for this issue?

I just stuck on the same error on my bitbucket pipeline. reviewdog: failed to post annotations: failed to create code insights annotations: bitbucket Cloud API error: 400 Bad Request

@wizardishungry
Copy link
Author

@pararang We're still seeing it as well; I haven't had time to dig into the code yet.

@kade-dentel
Copy link

kade-dentel commented Nov 23, 2022

I was seeing this as well. In my case, the issue was that bitbucket doesn't accept annotations without a message. My linter was not reporting a message, so I had to use sed s/$/"; Code style issue."/ to add a generic message and also update my error format to include %m to capture the message.

Can we add a specific error when reviewdog cannot post an annotation because of a missing message?

From bb docs (summary is the same thing as message):

image

@wizardishungry
Copy link
Author

I managed to get the underlying error message from Bitbucket:

{"key": "report-service.general.bad-request", "message": "The summary field cannot contain more than 450 characters.", "arguments": {}}

Suggestions as to how to fix this right now (by reviewdog configuration) would be welcomed, but it would also be helpful to be able to see underlying error messages.

CreateOrUpdateAnnotations in service/bitbucket/cloud_api_client.go:

	_, resp, err := c.cli.ReportsApi.
		BulkCreateOrUpdateAnnotations(ctx, req.Owner, req.Repository, req.Commit, req.ReportID).
		Body(c.helper.BuildAnnotations(req.Comments)).
		Execute()

It appears that this call returns the error in question and checkAPIError seeing as its error argument is not nil, declines to put the body of the error into the message. It would be helpful to see the body of error messages. I believe whatever error type is being returned by the OpenApi go-bitbucket library does satisfy interface{ Body() []byte }.

@wizardishungry
Copy link
Author

I patched the code to truncate annotation summaries to 450 characters and now bitbucket is giving me:

{"key": "report-service.annotation.max-annotations", "message": "Too many annotations associated with report with ID /{58263add-5b41-51b5-ae37-e287ca31c86f}", "arguments": {}}
diff --git a/service/bitbucket/cloud_api_helper.go b/service/bitbucket/cloud_api_helper.go
index 62d366f..c46c816 100644
--- a/service/bitbucket/cloud_api_helper.go
+++ b/service/bitbucket/cloud_api_helper.go
@@ -35,10 +35,17 @@ func (c *CloudAPIHelper) BuildAnnotations(comments []*reviewdog.Comment) []bbapi
 }
 
 func (c *CloudAPIHelper) buildAnnotation(comment *reviewdog.Comment) bbapi.ReportAnnotation {
+
+       const MAX_SUMMARY_LENGTH = 450
+
        data := bbapi.NewReportAnnotation()
        data.SetExternalId(externalIDFromDiagnostic(comment.Result.Diagnostic))
        data.SetAnnotationType(annotationTypeCodeSmell)
-       data.SetSummary(comment.Result.Diagnostic.GetMessage())
+       summary := comment.Result.Diagnostic.GetMessage()
+       if len(summary) > MAX_SUMMARY_LENGTH {
+               summary = summary[:MAX_SUMMARY_LENGTH]
+       }
+       data.SetSummary(summary)
        data.SetDetails(fmt.Sprintf(`[%s] %s`, comment.ToolName, comment.Result.Diagnostic.GetMessage()))
        data.SetLine(comment.Result.Diagnostic.GetLocation().GetRange().GetStart().GetLine())
        data.SetPath(comment.Result.Diagnostic.GetLocation().GetPath())

I'm not convinced I'm exceeding the annotations limit (1000?) – something else may be at foot.

@wizardishungry
Copy link
Author

https://developer.atlassian.com/server/bitbucket/how-tos/code-insights/

It is worth considering the behavior of the tool adding annotations to a report, as behavior such as re-running a build could result in duplicate annotations being created. In scenarios where this is an option we recommend that all the annotations are first deleted in bulk before new ones are created.

@wizardishungry
Copy link
Author

Lookin at the reviewdog docs - it looks like bitbucket only supports nofilter - so if you exceed 1000 warnings, you will get an error.

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

No branches or pull requests

3 participants