Debugging and errors
Writing Hurl code is not particularly easy since it's so different from what we usually are writing. Unfortunately, the interpreter is not very helpful when we make mistakes: it simply panics at whatever line in the interpreter, which gives you essentially no useful information about what went wrong.
Here are some of the techniques I found helpful while writing and debugging a few programs in Hurl:
- Start small. If you are doing something with a large input, try a small one first so you can more easily trace the execution.
- Add print statements. You can put print statements everywhere to figure out what values are where and where things are going wrong.
- Limit recursion depth. If you run into stack overflows, this is probably because you've looped too far and blown the stack! The stack size is limited by the operating system so if you run into this, you're going to need to work around it by limiting your recursion depth. Nested loops are a nice way to chunk up iteration and limit the max depth.
And then just read your program again and again and you'll find the error eventually! Or you won't, and that's okay. It might also plausibly be an interpreter bug, so feel free to email me for help debugging.