Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Line numbers shown as NaN in stack trace when compiling CoffeeScript inside CoffeeScript #4558

Closed
wastl-junior opened this issue May 30, 2017 · 3 comments
Labels

Comments

@wastl-junior
Copy link

When calling the following script lineNumbers.coffee:

cs = require 'coffee-script'
cs.compile ""

throw new Error "Some Error"

using coffee lineNumbers.coffee
I get the following stacktrace:

Error: Some Error
    at Object.<anonymous> (F:\test\lineNumbers.coffee:NaN:NaN)
    at Object.<anonymous> (F:\test\lineNumbers.coffee:NaN:NaN)
    at Module._compile (module.js:NaN:NaN)
    at Object.exports.run (F:\test\node_modules\coffee-script\lib\coffee-script\coffee-script.js:NaN:NaN)
    at compileScript (F:\test\node_modules\coffee-script\lib\coffee-script\command.js:NaN:NaN)
    at compilePath (F:\test\node_modules\coffee-script\lib\coffee-script\command.js:NaN:NaN)
    at Object.exports.run (F:\test\node_modules\coffee-script\lib\coffee-script\command.js:NaN:NaN)
    at Object.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\coffee-script\bin\coffee:NaN:NaN)
    at Module._compile (module.js:NaN:NaN)
    at Object.Module._extensions..js (module.js:NaN:NaN)
    at Module.load (module.js:NaN:NaN)
    at tryModuleLoad (module.js:NaN:NaN)
    at Function.Module._load (module.js:NaN:NaN)
    at Module.runMain (module.js:NaN:NaN)
    at run (bootstrap_node.js:NaN:NaN)
    at startup (bootstrap_node.js:NaN:NaN)
    at bootstrap_node.js:NaN:NaN

When commenting the compile call out:

cs = require 'coffee-script_1_12_1_works'
#cs.compile ""

throw new Error "Some Error"

I get a reasonable line numbers:

Error: Some Error
    at Object.<anonymous> (F:\test\lineNumbers.coffee:4:7)
    at Object.<anonymous> (F:\test\lineNumbers.coffee:1:1)
    at Module._compile (module.js:571:32)
    at Object.exports.run (F:\test\node_modules\coffee-script\lib\coffee-script\coffee-script.js:173:23)
    at compileScript (F:\test\node_modules\coffee-script\lib\coffee-script\command.js:224:29)
    at compilePath (F:\test\node_modules\coffee-script\lib\coffee-script\command.js:174:14)
    at Object.exports.run (F:\test\node_modules\coffee-script\lib\coffee-script\command.js:98:20)
    at Object.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\coffee-script\bin\coffee:15:45)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)
    at bootstrap_node.js:542:3

This occurs using coffee-script 1.12.6. This behaviour is new, everything works correctly using coffee-script 1.12.1 and below. I also get proper line numbers using the newest coffeescript version when I execute the file using node -r coffee-script/register lineNumbers.coffee

@GeoffreyBooth
Copy link
Collaborator

Can you narrow down when this broke?

The coffee command is intended primarily for compiling and debugging, and is not as full featured as running via Node.

@GeoffreyBooth GeoffreyBooth changed the title Linenumbers crash when compiling coffeescript inside coffeescript CLI: Line numbers shown as NaN in stack trace when compiling coffeescript inside coffeescript Jun 6, 2017
@GeoffreyBooth GeoffreyBooth changed the title CLI: Line numbers shown as NaN in stack trace when compiling coffeescript inside coffeescript CLI: Line numbers shown as NaN in stack trace when compiling CoffeeScript inside CoffeeScript Jun 6, 2017
@BrownBear2
Copy link

BrownBear2 commented Jun 6, 2017

it seems to be related to this pull request #4428

the problem is, that sourceMaps['< anonymous >'] is defined by running coffee and then is always returned for any file:
https://github.com/jashkenas/coffeescript/blob/master/src/coffee-script.coffee#L363

quick workarounds would be to set options.filename to anything but anonymous or to set options.sourceMap to false

GeoffreyBooth added a commit to GeoffreyBooth/coffeescript that referenced this issue Aug 16, 2017
…ps, more careful lookup of source maps especially for CoffeeScript code compiled within a Coffee script (. . . within a Coffee script, etc.)
GeoffreyBooth added a commit that referenced this issue Aug 23, 2017
…ript (#4645)

* Don't throw an error in the console when loading a try: URL

* Handle the possibility of compiling multiple scripts with the same filename, or multiple anonymous scripts

* Fix #4558: Much more robust caching of sources and source maps, more careful lookup of source maps especially for CoffeeScript code compiled within a Coffee script (. . . within a Coffee script, etc.)

* Reimplement `cake release` to just use the shell to avoid the issues plaguing that command (something to do with module caching perhaps)
@GeoffreyBooth
Copy link
Collaborator

Fixed by #4645.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants