How to get better error reporting with typst.ts? #485
-
Hi, I am constantly using this amazing library and it has been great, thanks for maintaining it. I have a question with the error reporting part of it. I was using another product around - typst-preview, I think to which you are also a maintainer. I tried compiling some of my documents in it, and it very efficiently directs to the line the error happening, along with the line number, for example -
When I tried compiling a document with my typst.ts setup, it reported error efficiently, but I think there are some more processing required to direct to the line number, for example, catch the error and print it to the console, it looks like this
If my understanding is correct, Span(xyz) does exactly that. Is it possible to translate this to point to the line number the error is happening? If it is something that needs to be done on my part, can you guide me where I can look it up? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Sorry about late, I was on vacation.
You are correct, we currently have full information about diagnostics. But typst.ts still doesn't provide a way to access that information. It needs carefully design. For design of processing diagnostics, there are three different directions.
try {
const doc = compile("");
} catch(e) {
// process error here with `e` that stores information from rust.
void(e.span);
if (e.free) { // otherwise we will get memory leak...
e.free();
}
} |
Beta Was this translation helpful? Give feedback.
-
I have created an issue for tracking design of diag API, #486. |
Beta Was this translation helpful? Give feedback.
Sorry about late, I was on vacation.
You are correct, we currently have full information about diagnostics. But typst.ts still doesn't provide a way to access that information. It needs carefully design.
For design of processing diagnostics, there are three different directions.
typst-preview uses rust API of typst.ts, so there is no problem for exporting diagnostics information. typst-preview can use the typst crate's
SourceDiagnostics
directly, and it can convertSpan
inside ofSourceDiagnostics
by World api easily.I experiment a bit on typst.node for API design of js binding, it can raise an error that stores raw spans, a…