Consume comments changes#35934
Conversation
|
@ahsonkhan I have checked in the fixes for review comments. Please check when you get a moment. Thanks! |
|
@ahsonkhan appreciate your review comments on this one! Thanks! |
ahsonkhan
left a comment
There was a problem hiding this comment.
Some feedback and questions. Apologies for the delayed review.
b2bdff6 to
aa6b47f
Compare
|
@ahsonkhan I have uploaded the entirely reworked logic. Please review referencing the original logic before this PR. |
|
@ahsonkhan the code is ready for review with all the changes. Could you please review it. It also has fix for the existing issue that I mentioned in here. |
|
@ahsonkhan I have fixed the latest review comment as well and resolved the code conflict. Please check. |
@WinCPP, thanks for your patience and effort. Much appreciated. We are almost at the finish line :) I just have a nit and a leftover question around consistency when throwing particular exception messages. |
|
Sorry I completely missed this communication. Will do it today. Thanks for
reminder :-)
…On Thu, May 16, 2019 at 8:25 AM Ahson Khan ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
src/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs
<#35934 (comment)>:
> if (localBuffer.Length == 0)
{
if (IsLastSpan)
{
- ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfValueNotFound, JsonConstants.Slash);
+ ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.UnexpectedEndOfDataWithinStartOfComment);
@WinCPP <https://github.com/WinCPP> - let me know when you plan to
address this final feedback + resolve the merge conflict. Thanks for your
effort dealing with all the subtleties.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#35934?email_source=notifications&email_token=ACEH6MX3T2DUXR7PC6LWBPLPVTEK5A5CNFSM4G46TBOKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOBYZAB4I#discussion_r284522538>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACEH6MRQU3WGVFN2V5BVFSLPVTEK5ANCNFSM4G46TBOA>
.
|
ahsonkhan
left a comment
There was a problem hiding this comment.
Returning "end of data" exception message for incorrect character within a comment is not correct.
| else | ||
| { | ||
| ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.UnexpectedEndOfDataWithinStartOfComment); | ||
| ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.UnexpectedEndOfDataWhileReadingComment); |
There was a problem hiding this comment.
Use InvalidCharacterAtStartOfComment here. UnexpectedEndOfDataWhileReadingComment doesn't make sense for this case.
OR, better yet: since this is "Skip" and not "Consume", keep ExpectedStartOfValueNotFound here.
There was a problem hiding this comment.
Skip in Multi-segment does the right thing. Single-segment should do the same:
There was a problem hiding this comment.
The value sent is JsonConstants.Slash but that could be an * as well, which we don't know yet because it is not there. Essentially, it could be / or * and we don't have placeholders for two characters in that exception. This is where all my thought process to have all those separate exception messages started.
So was the original exception that just emitted a / correct?
There was a problem hiding this comment.
At line 2179 and 2186, the buffer length is already zero. We don't know the intention yet whether it was to follow with a / or * for single / multi line comment respectively. That is why I considered ExpectedStartOfComment as a wrong message. Because it expects a / (only). Why not *? We can't say anything if there is nothing!
At 2206, I did get confused because the exception resource name says ExpectedStartOfValueNotFound where as the actual message is <value> is invalid start of a value.. Perhaps, the exception resource name should be UnexpectedStartOfValue to align with the contents of exception message.
There was a problem hiding this comment.
I see the confusion. Maybe I can try to help explain my perspective.
The value sent is
JsonConstants.Slashbut that could be an*as well, which we don't know yet because it is not there.
The reason why value sent is JsonConstants.Slash is because before calling Skip(), we already saw a slash (that's what got us into the Skip method). See:
corefx/src/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs
Lines 895 to 897 in 6f9570e
It doesn't matter if * follows next or /. Skip mode tries to ignore comments all together. So, the exception user sees is, "we saw / and then either we hit end of data or something invalid". / is not a valid start of value which is what we would expect (think of skip as if comments don't exist at all in JSON). That's why we have the ExpectedStartOfValueNotFound message.
That is why I considered
ExpectedStartOfCommentas a wrong message.
For "Skip" mode, I agree, we shouldn't return ExpectedStartOfComment. I am suggesting we return ExpectedStartOfValueNotFound. I don't think it makes sense for the user to see a comment related message when the user said "skip" them.
Let's say you have invalid JSON like this: {"property": /}. I expect an exception saying / is invalid start of a value. We should throw that regardless of whether the user was in "skip" or "disallow".
So was the original exception that just emitted a
/correct?
In my opinion, yes.
Perhaps, the exception resource name should be
UnexpectedStartOfValueto align with the contents of exception message.
Maybe, but I don't feel strongly about it. If you think it makes it clearer, I would be ok with renaming it.
There was a problem hiding this comment.
@ahsonkhan I get the idea now. Thank you for the clarification. Didn't realize the subtlety in two usages of one exception message.
I have submitted the changes. Hope I have finally got them as wanted. Thanks for patience.
|
@WinCPP, here are all the cases we need to be consistent on. Behavior of single-segment Skip/Consume should match the behavior of multi-segment Skip/Consume. For invalid or incomplete data, Skip should throw Consume should throw To summarize:
|
@WinCPP - thanks for the fix. Looks like the next step is #35705. |
* Consume comments changes * Fixed issues in branch splitting * Use sequence positions. Elaborate comments. * Reworked algos, review comment fixes * Fixed review comments * minor comment fix * Standardize exception messages * Clean up exception messages Commit migrated from dotnet/corefx@d72d720
Changes to ValueSpan / ValueSequence to exclude comment delimiters as per point 2 below,
Yes, it would.
Let's stage it in smaller, clearer chunks, where the change is isolated. So, in this order:
What do you think of this approach?
Unless this is blocking some of the work above, I would file a new issue for this and investigate/fix separately. Some questions we likely want to resolve first: What does Json.NET return for line number when comments end with just
\r(for Windows vs Unix)? Do we double count line number\r\nor treat it as a single line increment?cc @JamesNK
Originally posted by @ahsonkhan in #35705