Skip to content

Commit 2d5499a

Browse files
committed
misc: Print document when fatal error is encountered
Add extra context around the document being processed. This helps pinpoint fatal errors that may come from e.g. parsing of documents but before did not have a reference to the document that failed to parse.
1 parent 405e442 commit 2d5499a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

Marksman/Doc.fs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,30 @@ type Doc = {
5656
| :? Doc as other -> (this :> IComparable<_>).CompareTo(other)
5757
| _ -> failwith $"Comparison with non-Doc type: {obj}"
5858

59+
exception DocumentError of doc: RootedRelPath * cause: exn with
60+
override this.Message =
61+
$"Error while processing {RootedRelPath.filename this.doc}{Environment.NewLine}{this.cause.Message}"
62+
5963

6064
module Doc =
6165
open Marksman.Syms
6266

6367
let logger = LogProvider.getLoggerByName "Doc"
6468

6569
let mk parserSettings id version text =
66-
let structure = Parser.parse parserSettings text
67-
let index = Index.ofCst (Structure.concreteElements structure)
68-
69-
{
70-
id = id
71-
version = version
72-
text = text
73-
structure = structure
74-
index = index
75-
}
70+
try
71+
let structure = Parser.parse parserSettings text
72+
let index = Index.ofCst (Structure.concreteElements structure)
73+
74+
{
75+
id = id
76+
version = version
77+
text = text
78+
structure = structure
79+
index = index
80+
}
81+
with exn ->
82+
raise (DocumentError(id.Path, exn))
7683

7784
let id { id = id } = id
7885
let text doc = doc.text

0 commit comments

Comments
 (0)