Blog

Variable error del catch en una saga no es directamente visible en Chrome

Variable error del catch en una saga no es directamente visible en Chrome

Tengo un try/catch(error) dentro de una saga, pero la variable error del catch no es directamente visible. Al hacer hover con el puntero del ratón no aparece nada, y al añadirlo manualmente a la sección «Watch» se muestra <not available>. Sin embargo, el console.log(error) aparece correctamente en la consola:

En el Call Stack se puede apreciar la llamada a tryCatch de regeneratorRuntime de Babel:

regenerator-runtime is the runtime support for compiled/transpiled async functions. (It may well have other uses, but this is the predominant one.)

When you use a compiler like Babel that compiles modern JavaScript into earlier JavaScript (a process sometimes called transpiling), one of the things you can do is compile async functions to something that will run on JavaScript engines that don’t support async functions (such as the increasingly-irrelevant IE11). Babel does the syntax transformation, but the resulting code relies on runtime support from regenerator-runtime.

https://stackoverflow.com/a/65378580

Creo que la falta de visibilidad de error pueda ser por alguna limitación del «source map» de Babel:

That looks like what happens when you’re transpiling async functions for target environments that don’t have them. They end up being so thoroughly transformed so that regeneratorRuntime can handle them that even source maps can’t help. I solve it by setting up the project not to transpile async functions during dev and debugging on a modern browser that supports them directly. Then we do testing on target pre-async browsers with the production (transpiled) build. If we have to track down a problem that only happens when transpiling (very rare), we turn it back on for dev and insert debugger; statements. 😐

https://stackoverflow.com/a/62215657

Curiosamente, tal y como se explica aquí, al hacer let myError = error, sigo sin verla con el puntero del ratón pero sí aparece en el Watch, aunque sólo el contenido, sin el nombre de la variable (directamente : TypeError en lugar de myError: TypeError):