Halite Home

Debugging your bot in Node.js


I thought I'd share a few things I learned while debugging my bot in Nodejs.

Runtime Exceptions

As we all know you cannot send messages to standard out so the next most obvious option is logging to a file.

It was somewhat difficult to get Nodejs to flush the logs before exiting.
Here is a gist with the module I currently use.

Note: You will need to use npm to install winston

npm install winston

Setting the timeout gives node a moment to go back and flush the logs before it exits.
It also will not affect your bot by timing out in regular operation, but don't take my word for it, make sure that is true for yourself!

Now during local testing you can tell when you get a runtime exception now because your bot will timeout like this

Bot #1 timeout or error (Unix) 0

You can find your unhandled exception in the log file.

Compile Exceptions

If you're using my logging method above, you can tell when you get a compile time exception because you will get this message on turn 1

Bot sent an invalid character - ejecting from game.

In this case the way to find your exception is run just your bot and not halite. This is the same line you use in your call to halite.
Mine looks like this

node MyBot.js

This will print to standard out any compile time errors you have.