fsprojects / FSharp.Formatting

F# tools for generating documentation (Markdown processor and F# code formatter)
https://fsprojects.github.io/FSharp.Formatting/
Other
465 stars 156 forks source link

Unhelpful error message when you try to include a snippet that doesn't exist #673

Open nhirschey opened 3 years ago

nhirschey commented 3 years ago

If I try to (*** include:sample ***) but I misspell it as (*** include:smaple ***) I get an error message like what is below that is not very helpful for finding where the spelling error is.

System.Collections.Generic.KeyNotFoundException: The given key 'Microsoft.FSharp.Core.CompilerServices.RuntimeHelpers+StructBox`1[Microsoft.FSharp.Core.FSharpChoice`2[Microsoft.FSharp.Collections.FSharpList`1[FSharp.Formatting.CodeFormat.Line],System.String]]' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Microsoft.FSharp.Core.ExtraTopLevelOperators.DictImpl`3.System.Collections.Generic.IDictionary<'Key, 'T>.get_Item(TKey x) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\fslib-extra-pervasives.fs:line 54
   at FSharp.Formatting.Literate.Transformations.replaceLiterateParagraph$cont@382(LiterateProcessingContext ctx, IDictionary`2 formatted, LiterateParagraph special, Unit unitVar) in C:\Users\Kevin\source\repos\fsprojects\FSharp.Formatting\src\FSharp.Formatting.Literate\Transformations.fs:line 385
   at FSharp.Formatting.Literate.Transformations.replaceLiterateParagraph(LiterateProcessingContext ctx, IDictionary`2 formatted, MarkdownParagraph para) in C:\Users\Kevin\source\repos\fsprojects\FSharp.Formatting\src\FSharp.Formatting.Literate\Transformations.fs:line 371

It would be much more useful if I was told which key could not be found. I believe the issue is this code here https://github.com/fsprojects/FSharp.Formatting/blob/db90aeb4a5e4c72963cedf2742346ababea0b252/src/FSharp.Formatting.Literate/Transformations.fs#L385

Perhaps with something like the following would be better?

| CodeReference (ref, _) -> 
    match Map.tryFind (Choice2Of2 ref) formatted with
    | Some x -> Some x
    | None -> failwith $"Could not find reference {Choice2Of2 ref}"
dsyme commented 3 years ago

Yes that's not so useful :-)

Perhaps with something like the following would be better?

Yes that would be much better