loading x elements...

This page explains how to debug Programs on Elody.

The basic problem when something goes wrong with Elody is that there are several possible reasons for it:

  1. Your Rules do not work correctly, so your Programs never even get called correctly.
  2. Your Programs do not work correctly.
  3. Everything you wrote does work correctly, but someone else's code does not work like you expect and that interferes with your Rules.

A Scenario Plan for development

The first step to debug properly is to set up a separate Scenario Plan to create a testing environment.

By defining explicitly which Rules by which developers should be trusted, you can remove randomness and make everything more reliable.

You can also use the Tag !default_program_version to tell Elody that it should use development versions of your Programs, not release versions. This way, you can debug without accidentally changing what other people see when they run your Scenario Plans.

We have previously uploaded Programs like this:
lod-tools upload-program -n "The_name_of_my_program" -f "/path/to/a/folder/containing/the/program" -r
To upload a development version of a Program, just remove the '-r' flag from this command.

Have a look at these two Scenario Plans. The first is the one from this example, the other is a debugging version of the same:

Setting up the lod-executor

If the bug happens in a Program, it would normally be very difficult to find the reason for the bug, since the Program is executed on the Elody server.

You can install and configure the lod-executor to fix this: With the lod-executor you can run all Programs that would normally run on the Elody servers locally, on your own computer.

Check out this page for instructions for how to install, configure, and use the lod-executor.

Using Developer Mode

The first step in identifying the bug is backtracking what Elody did that lead to the erroneous behavior.

To do this, open Developer Mode in a running Scenario by clicking the button 'Enter Developer Mode' on the left.

You can find more information about how to use Developer Mode here. It also explains how you can use Developer Mode to backtrack what happened, and what caused Elody to make the decisions it did.

Debugging a Program locally

If you find that the bug was caused by a Program, you can use the lod-executor in conjunction with the lod-tools to debug it.

The lod-executor creates a folder on your computer for each step involving a Program execution. You can use the data in this folder to reproduce the buggy Program execution. This way, you can test changes to your Program immediately and don't have to upload a new version and start a new Scenario every time you make a change.

To do this, use the following command:

lod-tools test-program -p /path/to/program -prep /path/to/original/folder -e /path/to/testing/folder -l

Where "/path/to/original/folder" is the folder used by the lod-executor for the Program execution that went wrong. You can find this folder as follows: Go to the root path you configured the lod-executor with. Open the folder whose name is "execX" where X is the ID of the Scenario (you can find this number in the URL of the open Scenario). Your target folder is "stepY" where Y is the step in which the Program was executed. The step of the program execution can be found in Developer Mode.

This command will execute your Program again with the same inputs that it had in the Scenario. Any error messages or log statements will be shown in the console. You can also put print() statements in your Program, which will be put into a log file by the lod library.

Finally, if you have problems with debugging, don't hesitate to ask for advise on the forum!

Once you are done with debugging, don't forget to upload the program again with the '-r' option to mark it as a release version.

Advice: Rapid testing of a new program

When you write a Program that is complex enough, it probably won't work properly on the first try.

So here is some practical advice for writing new Programs:

  • Start by creating a dummy Program that expects the correct inputs, but doesn't do anything.
  • Write the Rule and set up a minimalistic Scenario Plan for testing your Program.
  • Run the Scenario Plan until the point where the Program is run. It will obviously fail, since the Program's logic is not implemented yet.
  • Now ignore Elody's web interface and switch to the lod-tools. Use lod-tools test-program to test the Program.
  • Implement the Program's logic, while testing it with lod-tools test-program until it works.
  • Once the Program works, upload it and run the Scenario again.

This is a much faster way to write and test things than running the whole Scenario each time. It is especially useful if you have multiple Programs that depend on each other and take time to run.