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

Add line and colum numbers to JSON errors thrown by HTTP endpoints. #4012

Merged
merged 2 commits into from
Sep 27, 2019

Conversation

martinmr
Copy link
Contributor

@martinmr martinmr commented Sep 17, 2019

@martinmr martinmr requested review from manishrjain and a team as code owners September 17, 2019 22:32
Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ A review job has been created and sent to the PullRequest network.


@martinmr you can click here to see the review status or cancel the code review job.

@martinmr
Copy link
Contributor Author

Example output:

➜  dgraph-linux-amd64 curl -H "Content-Type: application/json" -X POST "localhost:8180/mutate?commitNow=true" -d '{
  "set": [
    {
      "uid": "0x1",
      "friends_with",: [
        {
          "uid": "0x3",
          "friends_with|good": false,
        }
      ]
    }
  ]
}'
{"errors":[{"message":"Error parsing JSON at line 5, character 23: invalid character ',' after object key\n","extensions":{"code":"ErrorInvalidRequest"}}]}% 

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good and conforms to description. Added comments inline for simplification and adding the link for future reference.


Reviewed with ❤️ by PullRequest

@@ -312,7 +313,8 @@ func mutationHandler(w http.ResponseWriter, r *http.Request) {
case "application/json":
ms := make(map[string]*skipJSONUnmarshal)
if err := json.Unmarshal(body, &ms); err != nil {
x.SetStatus(w, x.ErrorInvalidRequest, err.Error())
jsonErr := convertJSONError(string(body), err)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems these lines are duplicated across multiple functions -- I suggest creating another wrapper which encapsulates the two lines you added here and other places

@@ -577,3 +579,52 @@ func (sju *skipJSONUnmarshal) UnmarshalJSON(bs []byte) error {
sju.bs = bs
return nil
}

// convertJSONError adds line and character information to the JSON error.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a link to the article as a part of the comment for reference

Copy link
Contributor Author

@martinmr martinmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @campoy, @manishrjain, and @pullrequest[bot])


dgraph/cmd/alpha/http.go, line 316 at r1 (raw file):

Previously, pullrequest[bot] wrote…

It seems these lines are duplicated across multiple functions -- I suggest creating another wrapper which encapsulates the two lines you added here and other places

Not doing this for just a couple of lines.


dgraph/cmd/alpha/http.go, line 583 at r1 (raw file):

Previously, pullrequest[bot] wrote…

I would add a link to the article as a part of the comment for reference

Done.

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r2.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @campoy and @pullrequest[bot])

@martinmr martinmr merged commit 3039115 into master Sep 27, 2019
@martinmr martinmr deleted the martinmr/json-error-lines branch September 27, 2019 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Parsing error is incorrect
2 participants