-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
There was a problem hiding this 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.
Example output:
|
There was a problem hiding this 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) |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r2.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @campoy and @pullrequest[bot])
Implementation idea taken from
https://adrianhesketh.com/2017/03/18/getting-line-and-character-positions-from-gos-json-unmarshal-errors/
Fixes #3965
This change is