dart-lang / source_maps

A package to programmatically manipulate source maps.
https://pub.dev/packages/source_maps
BSD 3-Clause "New" or "Revised" License
16 stars 14 forks source link

How do I use generated source maps in my server application? #44

Closed dustin-graham closed 4 years ago

dustin-graham commented 4 years ago

My setup may be a bit unique but I'm hoping I can get some guidance here.

I have working Firebase Cloud Functions written in Dart and compiled with dart2js and working with Node. I'm using the following package to make this happen:

https://pub.dev/packages/firebase_functions_interop https://pub.dev/packages/firebase_admin_interop

Everything works great except that stack traces aren't human readable. I can see the source map that is generated but I can't seem to figure out how to get that to help make our printed stack traces usable. Any tips?

sigmundch commented 4 years ago

Hi @dustin-graham - indeed, sourcemaps can be used to extract some useful data from stack traces. Browsers have built-in support to parse source-maps within devtools, so many people get a lot of the data they need by using the debugger and ensuring the source map can be downloaded by the debugger. Many team also post-process stacktraces in their servers together with the source-map. There are a couple packages that you can use for this purpose (they use the source_maps package to parse the data and reconstruct more readable stack traces.)

The main package I'd recommend for now is: source_map_stack_trace. It should do what you need out of the box.

There is another piece of code that is unforunatelly not yet published as a package in pub (see https://github.com/dart-lang/sdk/tree/master/pkg/dart2js_tools). It is similar to the other package, but it has some additional logic to understands an extension dart2js added to source-maps to unwind inlined calls and to map minified names in error messages. These additions can sometimes make debugging easier.

Hope this helps!