Debug mode for running .coffee scripts #558, #987 #1396
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Debug mode for running .coffee scripts #558, #987
Adds a --debug option for .coffee scripts that outputs more helpful error messages (mapping compiled .js lines of code to the input .coffee file's lines).
This branch should be considered experimental at the moment -- it serves as a proof-of-concept and to expose additional issues with adding debugging support to CoffeeScript. I.e., don't merge it into master :)
Current output:
--debug Output:
--debug
compiler option with line number comments, @andrewschaaf 's "FUGLY" option (though modified so that the end user never sees the ugly JS line number comments)Caveats
run
ning andeval
-ed .coffee scripts (see below)Here's the branch:
https://github.com/geraldalewis/coffee-script/tree/debug
Here's the commit:
geraldalewis@9d0fa7c
=What works=
Running .coffee files
Eval
...Sort of -- this works:
but this fails for some reason (some bug in the
DebugCSFile.error
, I think -- seems to happen if < 2 lines of .js)What doesn't work
There are a few classes of errors I'm struggling to get debug info from. I have no solutions at the moment, but some ideas below.
Errors in CoffeeScript
@jashkenas 's first question to me was what kind of output he'd see if there was an error in
src/scope.coffee
. I inserted a bug intoScope
's constructor (a call toundef()
), recompiled CoffeeScript, and ran coffee -bed 'i = 1'Clearly,
debug
didn't work -- we have the samenode.js
error message output, instead of the expected:My mistake was forgetting that
coffee
uses pre-compiled .js files to run CoffeeScript.debug
relies on CoffeeScript compiling a .coffee file -- the .coffee file needs to be present so that the executing .js file's line numbers can be mapped to their CoffeeScript source. Since we no longer have a reference to the originalscope.coffee
file, we don't have any way of associating the lines of code where an error occured inscope.js
.Compounding the issue: because
debug
needs to re-compile the source .coffee file(s) (to insert the line-number comments mapping the line of .js to its respective line of .coffee) a bug in thecompile
pipeline is a bug indebug
...Possible Solutions
cake build
ensures a clean, working copy of CoffeeScript is available even if a bug is introduced into its sourcecake build
Docco
Debugging Docco represents a subtly different class of issues than debugging CoffeeScript. Like CoffeeScript,
docco.coffee
has already been compiled todocco.js
whenbin/docco
require
s it:We have the same issue -- since we no longer have a reference to the original
.coffee
script, we don't have any way of associating the line of JavaScript code with its originating CoffeeScript line.Possible solutions:
run
docco
via bin/coffeemodify
command.coffee
run
to allow args to be sent via "<" to the running script if the-d
option is set:--debugsource
flag (oof?)not sure how this would work exactly, but some loose ideas:
debugsource
points to the .coffee source file or src/ folder for the running scriptif an error is encountered in the
node.js
runtimeuse
process.on 'uncaughtException'
to catch it and save details as "stack
"run
coffee-script.debug ( debugsource, stack ... )
(this recompiles the debugsource so that the CoffeeScript lines can be associated with their JS counterparts )
docco --debugsource=src/docco.coffee src/some_project.coffee