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

Reliable getTypeLink. #380

Merged
merged 1 commit into from
Jan 25, 2016
Merged

Reliable getTypeLink. #380

merged 1 commit into from
Jan 25, 2016

Conversation

jinlmsft
Copy link
Contributor

For

let getTypeLink (ctx:ReadingContext) undefinedLink

Before the change, when the link is undefined, the FSharp.Formatting will crash. The change will allow an undefinedLink to return None, and let the rest of the parsing completes.

For

let getTypeLink (ctx:ReadingContext) undefinedLink

Before the change, when the link is undefined, the FSharp.Formatting will crash. The change will allow an undefinedLink to return None, and let the rest of the parsing completes.
@tpetricek
Copy link
Member

Thanks a lot for this!

Is the call throwing any more specific exception, or do we need to catch all possible exceptions? The change looks good to me & I'll merge it, but if it throws something more specific, it would be good to handle that more precisely...

tpetricek added a commit that referenced this pull request Jan 25, 2016
@tpetricek tpetricek merged commit 32ddb7b into fsprojects:master Jan 25, 2016
@jinlmsft
Copy link
Contributor Author

It is throw by:

resolveCref

invalidArg "cref" (sprintf "the given cref: '%s' is invalid!" cref)

which crashes the program. The particular instance show the exception as:

the given cref: 'T:' is invalid!"

so cref is “T:”.

Generally, it will be much more helpful if FSharp.Formatting can print the line # and docs where the above issue occurs. The above exception when thrown doesn’t give any context on where the issue is located. It made me scratch my head and can’t figure out which documentation formatting is done right.

Thanks,
Jin

From: Tomas Petricek [mailto:[email protected]]
Sent: Monday, January 25, 2016 7:28 AM
To: tpetricek/FSharp.Formatting [email protected]
Cc: jinlmsft [email protected]
Subject: Re: [FSharp.Formatting] Reliable getTypeLink. (#380)

Thanks a lot for this!

Is the call throwing any more specific exception, or do we need to catch all possible exceptions? The change looks good to me & I'll merge it, but if it throws something more specific, it would be good to handle that more precisely...


Reply to this email directly or view it on GitHub #380 (comment) . https://github.com/notifications/beacon/AG7diO4HXoZMF-VVSaxcUcow6n-2ZSKRks5pdjaAgaJpZM4HJIUs.gif

@matthid
Copy link
Member

matthid commented Feb 1, 2016

So this happens when undefinedLink is empty. I would really like to know in which situations that happens. @jinlmsft can you provide a unit test for this (or a example where this happens)?

I don't feel like this is the correct fix, we should either change this condition to < instead of <=. But at the very least we should log the exception instead of just hiding it.

@jinlmsft
Copy link
Contributor Author

jinlmsft commented Feb 1, 2016

At the build when this triggers, it doesn’t print out the comment text (or the surrounding text in XML) that produce the issue. I have yet to figure out what comment triggers this.

Best,
Jin

From: Matthias Dittrich [mailto:[email protected]]
Sent: Monday, February 1, 2016 3:16 PM
To: tpetricek/FSharp.Formatting [email protected]
Cc: jinlmsft [email protected]
Subject: Re: [FSharp.Formatting] Reliable getTypeLink. (#380)

So this happens when undefinedLink is empty. I would really like to know in which situations that happens. @jinlmsft https://github.com/jinlmsft can you provide a unit test for this (or a example where this happens)?

I don't feel like this is the correct fix, we should either change this https://github.com/jinlmsft/FSharp.Formatting/blob/968ebac773f34ad7dee2284913bfed39d4c6d045/src/FSharp.MetadataFormat/Main.fs#L893 condition to < instead of <=. But at the very least we should log the exception instead of just hiding it.


Reply to this email directly or view it on GitHub #380 (comment) . https://github.com/notifications/beacon/AG7diIFqiQP44Z6A_pPVTf2YYm4ZWZKDks5pf97EgaJpZM4HJIUs.gif

matthid added a commit that referenced this pull request Feb 1, 2016
@matthid
Copy link
Member

matthid commented Feb 1, 2016

Ok I think I figured it out: The problem is markup like

Some empty ` ` inline comment

because the whitespace will be trimmed and then the "code" will be an empty string.

@jinlmsft
Copy link
Contributor Author

jinlmsft commented Feb 2, 2016

Can you clarify if 1) the comment need to be written in a corrected way, or 2) the program need to tolerate an empty string?

If the case is 1), it will be helpful to print out the XML line number that the problem occurs. As a developer, I can then figure out what inline comment needs to be properly formatted.

If the case is 2), then it will be great to catch the exception, and not expose it to the developer.

Thanks,
Jin

From: Matthias Dittrich [mailto:[email protected]]
Sent: Monday, February 1, 2016 3:58 PM
To: tpetricek/FSharp.Formatting [email protected]
Cc: jinlmsft [email protected]
Subject: Re: [FSharp.Formatting] Reliable getTypeLink. (#380)

Ok I think I figured it out: The problem is markup like

Some empty inline comment

because the whitespace will be trimmed and then the "code" will be an empty string.


Reply to this email directly or view it on GitHub #380 (comment) . https://github.com/notifications/beacon/AG7diGWo3phKdpZ8fLyiSYku97yAerz3ks5pf-hsgaJpZM4HJIUs.gif

@jinlmsft
Copy link
Contributor Author

jinlmsft commented Feb 2, 2016

The behavior repo again:

You may clone:

https://github.com/jinlmsft/Prajna/

and switch to branch FailedCommentXML.

Please use:

.\build.cmd Release

To build. During document generation, the exception will fire:

System.ArgumentException: the given cref: 'T:' is invalid!

Parameter name: cref

at FSharp.MetadataFormat.Reader.resolveCref@887(Dictionary2 registeredEntities, Dictionary2 entityLookup, Dictionar

y`2 niceNameEntityLookup, String cref) in c:\Tomas\Public\tpetricek\FSharp.Formatting\src\FSharp.MetadataFormat\Main.fs:

line 888

Thanks,
Jin

From: Jin MSFT [mailto:[email protected]]
Sent: Monday, February 1, 2016 4:12 PM
To: 'tpetricek/FSharp.Formatting' [email protected]; 'tpetricek/FSharp.Formatting' [email protected]
Subject: RE: [FSharp.Formatting] Reliable getTypeLink. (#380)

Can you clarify if 1) the comment need to be written in a corrected way, or 2) the program need to tolerate an empty string?

If the case is 1), it will be helpful to print out the XML line number that the problem occurs. As a developer, I can then figure out what inline comment needs to be properly formatted.

If the case is 2), then it will be great to catch the exception, and not expose it to the developer.

Thanks,
Jin

From: Matthias Dittrich [mailto:[email protected]]
Sent: Monday, February 1, 2016 3:58 PM
To: tpetricek/FSharp.Formatting <[email protected] mailto:[email protected] >
Cc: jinlmsft <[email protected] mailto:[email protected] >
Subject: Re: [FSharp.Formatting] Reliable getTypeLink. (#380)

Ok I think I figured it out: The problem is markup like

Some empty inline comment

because the whitespace will be trimmed and then the "code" will be an empty string.


Reply to this email directly or view it on GitHub #380 (comment) . https://github.com/notifications/beacon/AG7diGWo3phKdpZ8fLyiSYku97yAerz3ks5pf-hsgaJpZM4HJIUs.gif

@matthid
Copy link
Member

matthid commented Feb 2, 2016

To clarify: 2) The tool needs to properly handle this case.
But IMHO it's better to not even throw the exception at all.

FYI:
Besides that we already track error messages we need to improve here: #370

The problem there is that we need to do some major code changes (and probably a lot of breaking changes) to add line/column information to the parsed data structures. While we can probably improve the situation for the standalone markup parser (with some additional arguments) we cannot simply do the same for the Literate and the Metadata libraries.

@jinlmsft
Copy link
Contributor Author

jinlmsft commented Feb 2, 2016

It you can print the surrounding text in XML that cause the exception, that may be very helpful as well. I can then do a search in the XML file to find what causes the problem.

Jin

From: Matthias Dittrich [mailto:[email protected]]
Sent: Tuesday, February 2, 2016 9:29 AM
To: tpetricek/FSharp.Formatting [email protected]
Cc: jinlmsft [email protected]
Subject: Re: [FSharp.Formatting] Reliable getTypeLink. (#380)

To clarify: 2) The tool needs to properly handle this case.
But IMHO it's better to not even throw the exception at all.

FYI:
Besides that we already track error messages we need to improve here: #370 #370

The problem there is that we need to do some major code changes (and probably a lot of breaking changes) to add line/column information to the parsed data structures. While we can probably improve the situation for the standalone markup parser (with some additional arguments) we cannot simply do the same for the Literate and the Metadata libraries.


Reply to this email directly or view it on GitHub #380 (comment) . https://github.com/notifications/beacon/AG7diEzTxgodHhCEXPxTirXjStVLZXazks5pgN7GgaJpZM4HJIUs.gif

matthid added a commit that referenced this pull request Feb 3, 2016
add test for #380 and change the fix.
@matthid
Copy link
Member

matthid commented Feb 3, 2016

@jinlmsft The exception should no longer happen in the current (and future) versions :)

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.

3 participants