Skip to content

Commit eb2c8ef

Browse files
github-actions[bot]Repo AssistCopilot
authored
Improve error message when CodeReference snippet is not found (#982)
When using (*** include:name ***) with a misspelled or undefined snippet name, the previous code threw a cryptic KeyNotFoundException. Now it throws a clear message indicating which snippet name was not found and how to define it. Fixes #673 Co-authored-by: Repo Assist <repo-assist@github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ac6b562 commit eb2c8ef

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/FSharp.Formatting.Literate/Transformations.fs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,14 @@ module internal Transformations =
514514
match special with
515515
| RawBlock(lines, _) -> Some(InlineHtmlBlock(unparse lines, None, None))
516516
| LiterateCode(lines, _, _) -> Some(formatted.[Choice1Of2 lines])
517-
| CodeReference(ref, _) -> Some(formatted.[Choice2Of2 ref])
517+
| CodeReference(ref, _) ->
518+
match formatted.TryGetValue(Choice2Of2 ref) with
519+
| true, v -> Some v
520+
| false, _ ->
521+
failwithf
522+
"Could not find named code snippet '%s'. Check that it is defined with '(** define:%s ***)'."
523+
ref
524+
ref
518525
| FsiMergedOutputReference _
519526
| FsiOutputReference _
520527
| OutputReference _

0 commit comments

Comments
 (0)