0

I am in the process of ironing out my codebase so it can compile with ADVANCED_OPTIMIZATIONS on google's closure compiler.

After properly setting up the debugging environment required for this task (source map file, chrome, wrapping the compiled js file) i stumbled upon try catch issues. It appears that extensive use of try/catch statements in my codebase has backfired on me.

On almost all methods and functions i use a typical try { } catch(e) {ss.error(e);} statement, where ss.error() is a generic error handler that depending on environment either prints out debug stuff or reports back the exceptions...

In the process of ironing my codebase, when i get an error that i need to fix, what happens is that instead of having Chrome report the offending file and line, it points to the error handler ss.error(). Thus leaving me with no way of backtracing the problem. The ss.error() func however, does print where the problem originated from:

Error! type:TypeError at Db (/jsc/compiled.js:547:246) msg:Cannot call method 'ka' of undefined source:

After i get these type of errors i have to do two steps: 1. Fiddle with the compiled code at line 547 char 246 and try to figure out which part in my uncompiled code this refers to... 2. After i locate it, remove the try/catch blocks so i can directly and more clearly see what caused the error...

I must say i am not happy with this workflow and need to find an alternative that will both allow me to properly catch exceptions and debug my compiled and uncompiled code while retaining mind sanity =)

I was thinking of somehow using the Line:CharPosition info to query the source map and have the ss.error() function do the mapping to my uncompiled source code...

ideas?

thanpolas
  • 848
  • 1
  • 8
  • 20
  • Are you including a reference to your source map at the bottom of your compiled js files: `//@ sourceMappingURL=src/scripts.source.map.js `? Have you checked out the [Introduction to JavaScript Source Maps](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/)? – Christopher Peisert May 20 '12 at 20:02
  • 2
    Not the answer you are looking for, but the "debug" flag coupled with "formatting=PRETTY_PRINT" makes debugging much easier than dealing with source maps. – Chad Killingsworth May 21 '12 at 12:12
  • Also, not the solution you are looking for but you can also have your error handler capture the stack trace of the exception. – John May 21 '12 at 15:51
  • @ChadKillingsworth that might do the trick... – thanpolas May 21 '12 at 17:47
  • @John i do capture the stack trace, but it's not of much help in a compiled code... – thanpolas May 21 '12 at 17:47

1 Answers1

0

There is a java interface to the SourceMaps as part of the closure compiler. There are also JS implementations in various states of repair. I try to keep links to them up to date here:

http://code.google.com/p/closure-compiler/wiki/SourceMaps

For the Java implementation you simply load the source map using the SourceMapConsumerFactory, the interface is pretty simple.

John
  • 5,443
  • 15
  • 21