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

Debugging Hubot #648

Closed
ppatarinski opened this issue Feb 14, 2014 · 19 comments
Closed

Debugging Hubot #648

ppatarinski opened this issue Feb 14, 2014 · 19 comments

Comments

@ppatarinski
Copy link

Hi everyone,

I am new to node.js and coffee script. I have hubot running on my windows machine, but what I am trying to accomplish is debug hubot and any of the hubot scripts. How can I got about achieving that? So far I have gotten IntelliJ running and transpiling the coffee script to js. And my breakpoints hit in the index.js (or index.coffee), however stepping over the return new Robot line (line 25 in index.coffee) closes down the application.

Thank you
Paul

@troyswanson
Copy link

I'm dealing with the same kind of thing. Right now it's kind of a shot in the dark. I don't really have an answer for you - I'm mainly just +1'ing this issue.

@mdarveau
Copy link

The problem is that you are launching index.coffee which export the Robot class but does nothing else. hubot is started with the hubot script (https://github.com/github/hubot/blob/master/bin/hubot) which is a coffeescript file... without the .coffee extension. IntelliJ will not transpile it automatically.

I haven't tried to rename/transpile it but I did copy part of that into a separate .coffee file that I use as a launcher for debugging purpose. See https://github.com/MacKeeper/jobot/blob/master/run_hubot.coffee and https://github.com/MacKeeper/jobot/blob/master/run_localhost.coffee.

All of this is a little hackish but it works. Also, I had issues with libraries and IntelliJ transpiling so you might have to run "coffee -cmw ." in your projet or included node_modules.

I would love to have better support for node/coffeescript debugging in IntelliJ (is it better in 13?).

@ppatarinski
Copy link
Author

Hey Mac,

Thanks for the advice. I went with Visual Studio in the end

https://github.com/ppatarinski/Hubot_VisualStudio

But the approach I took should also work with IntelliJ.

The idea is you transpile the coffee script then you make the hubot.js file the start up file and debugging works :) Check out the repo above it should make more sense.

Cheers
Paul

@technicalpickles
Copy link
Member

Let's leave this open for a bit. Want to get something in the documentation. I also have had success using node-inspector for debugging.

@mdarveau
Copy link

BTW, when debugging in intellij, everything has to be transpilled to .js.
This causes issues not only because external scripts needs to be
transpilled before the debugger is launched but also because of the .coffee
file needs to be manually deleted. Otherwise, it tries to load the .coffee
file which fail since it assumes javascript. See "if ext is '.coffee' or (
ext is '.js' and not Fs.existsSync( Path.join( path, Path.basename( file,
ext ) + '.coffee' ) ) )" in Robot.loadFile.

On Sun, Feb 16, 2014 at 10:11 PM, Josh Nichols notifications@github.comwrote:

Let's leave this open for a bit. Want to get something in the
documentation. I also have had success using node-inspector for debugging.

Reply to this email directly or view it on GitHubhttps://github.com//issues/648#issuecomment-35225773
.

@ivolo
Copy link

ivolo commented Apr 26, 2014

Is there any way to debug using node debug and breakpoints?

@technicalpickles
Copy link
Member

Check out https://github.com/node-inspector/node-inspector

In your bin/hubot, you can basically replace exec node_modules/.bin/hubot "$@" with exec coffee --nodejs --debug node_modules/.bin/hubot "$@"

You'd need to have node-inspector in your package.json at some point. I'm not sure if you can set breakpoints in code (like ruby-debugger), but you can have it break at startup, and go in with chrome debugger to set some breakpoints before starting execution.

@michaelansel
Copy link
Collaborator

@geoffreyanderson I know you have been doing some pretty heavy hubot script development in IntelliJ; could you throw something in docs/scripting.md with details?

@victorhooi
Copy link

The book Automation and Monitoring with Hubot has a section on debugging.

I've just tested that myself, and it seems to work well. Basically, the steps are:

npm install -g node-inspector
node-inspector --no-preload --web-port 8123

Then, we can insert debugger in our code somewhere to setup a breakpoint. Then we run Hubot:

npm install -g coffeescript
coffee --nodejs --debug node_modules/.bin/hubot

Then, we visit http://127.0.0.1:8123/debug?port=5858 in our browser.

I think we should get this into the Hubot documentation. Also, somebody more experienced might have something to add.

@victorhooi
Copy link

I should also mention, I'm still not sure how to get access to things like robot or msg from within the node-inspector console though.

@geoffreyanderson
Copy link
Contributor

Since yeoman is used to generate a hubot and more hubot scripts are being converted to individual npm packages, there's less need to open the generated hubot repo in IntelliJ. What we've done is setup basic testing for new scripts in a separate repo and run most of that via the CLI since there seems to be a transpiling dependency for IntellIiJ to follow along.

I'll dig a little more and see if I can figure out a basic enough testing pattern with IntelliJ that plays nicely with this stuff. I think setting up the transpiler to throw the maps and JS files into a different directory (as per https://www.jetbrains.com/idea/help/transpiling-coffeescript-to-javascript.html#d305745e612) might help get around some issues with scripts getting double-loaded too.

@geoffreyanderson
Copy link
Contributor

When you get IntelliJ cleanly setup with a hubot checkout #845 makes any run/debug configurations simply fail. If you use #877 it appears to fix the problem with starting a runner from IntelliJ.

As for debugging from IntelliJ...it seems like the various permutations of a nodejs runner either can't be used in a debug mode or can only load a javascript console such that you can't access STDIN to invoke specific script commands (boo :( )

If folks still want to setup a new intellij project, the high-level set of steps are:

  • Generate your bot following Getting Started With Hubot
  • In IntelliJ, create a new empty project
  • set "Project Location" to your generated bot repository
  • Add your generated bot repository as a module for your project
    • In the "Project Structure" dialog, go to "Modules", click the "+" button then choose "Import modules"
      screen shot 2015-03-13 at 13 58 46
    • Choose "Create module form existing sources" and hit "Next"
    • Make sure the path to your generated bot repository is checked and hit "Finish"
    • You should now see your generated bot repository as a module in the project structure dialog.
  • Setup a file watcher to transpile coffeescript. To avoid issues with the transpiled JS files colliding with your .coffee files, set them up to use a js directory.
    • Set the "Arguments" field to --output $ProjectFileDir$/js/ --map --compile $FileName$
    • Set the "Output paths to refresh" field to $ProjectFileDir$/js/$FileNameWithoutExtension$.js:$ProjectFileDir$/js/$FileNameWithoutExtension$.map
  • Create a "Node.js" run configuration
    • Set the "Node interpreter" field to your coffeescript executable (e.g. /usr/local/bin/coffee)
    • Set the "Working directory" field to your generated bot repository path
    • set the "Javascript file" field to node_modules/.bin/hubot
    • screen shot 2015-03-13 at 14 16 25

@mecampbellsoup
Copy link

Does anyone know of a solid pattern for testing/debugging individual scripts (e.g. something.coffee) that one is writing to extend Hubot's capabilities? One of ours has broken and I'm struggling to do basic things like inspect objects, log output, etc.

@technicalpickles
Copy link
Member

For inspect based debugging in development, I usually include a line like:

console.log require('util').inspect thingToDebug

When using the shell adapter in development, that should be logged to the console.

If you are debugging something in production, you'll want to log with robot.logger instead, ie robot.logger.debug, robot.logger.error, robot.logger.info, etc. The default log level is info but you can change with the HUBOT_LOG_LEVEL environment variable.

@GGYaX
Copy link

GGYaX commented May 17, 2017

Hi Paul, try this out : a doc about setting up coffee in Intellij https://www.jetbrains.com/help/idea/2017.1/debugging-coffeescript.html. I remember the debug point can be set in coffee file directly.

@timkinnane
Copy link

x-post from Slack discussion on same topic...

I've had some success using atom and xatom-debug with unit tests, by running mocha with the --inspector flag, then setting xatom-debug to 'remote' mode, which watches the inspector port to debug remote processes. That will allow watching and reloading through the debugger or through a --watch flag on mocha and if you also run mocha with --inspector-brk, it won't execute tests until the debugger attaches, which is pretty neat. You still run into the problem of debugging compiled coffeescript. Trying to relate stack traces back to what's happening in your hubot coffee scripts is a major pain. No magic bullet yet, but I'm working on it.

@stale
Copy link

stale bot commented Aug 17, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@timkinnane
Copy link

Pinging this thread to keep stale bot's hands off it. I wouldn't consider it closed until there's a standard recommended and documented approach to running hubot with node debug enabled. Which I can hopefully provide myself, just haven't got to it yet.

@stale stale bot removed the stale label Aug 18, 2017
@stale
Copy link

stale bot commented Nov 16, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 16, 2017
@stale stale bot closed this as completed Nov 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

12 participants