Add source map support for stack traces#459
Conversation
|
Hmm I'm not sure I understand, source maps appear to work in stack traces in Chromium for me with the "Enable JavaScript source maps" option enabled in Devtools settings |
|
Hmm, that's odd. I do ofc get proper file references in in the server rendered response but any error created in the browser will just reference bundle.js in the stack trace. This minimal set up: // index.js
var choo = require('choo')
var html = require('choo/html')
var app = choo()
app.route('/', main)
app.use(store)
module.exports = app.mount('body')
function store (state) {
state.error = new Error('Something happened')
}
function main (state) {
return html`
<body>
<pre>${state.error.stack}</pre>
</body>
`
}when ran with |
|
ow, i see. I tried it with an uncaught error in devtools, and devtools in FF and chrome do support source maps. I kinda feel like printing the stack trace to the page rather than devtools is a rare use case? |
|
It might be an edge case but what I usually do is that I have a wrapper function for all my views which does a try/catch when rendering. If there's an error in development I print the stack trace to the DOM for debugging. To be clear; this is what my view wrappers usually look like module.exports = createView
function createView (view) {
return function (state, emit) {
var children, title
try {
children = view(state, emit)
} catch (err) {
children = html`
<main>
<h1>Something went wrong!</h1>
${process.env.NODE_ENV === 'development' ? html`
<pre>${err.stack}</pre>
` : null}
</main>
`
}
return html`
<body>
${state.cache(Header, 'header')}
${children}
${state.cache(Footer, 'footer')}
</body>
`
}
} |
This is a 🙋 feature
Add support for stack traces (in Chrome) using source-map-support.
Checklist
Context
Error stack traces would reference line numbers in the bundled javascript making it a hassle to track down where an error was thrown.
Before
After
Note:
brfscouldn't handle source-map-support checks for methods onfsso I had to exclude it from the transform.Semver Changes
Minor