Debugging in Montru - one line fix of that nasty unit commit issue
Channel: MiND
Date: 2020-01-03

Moving to harder tasks, real Dust/Montru development. After a short monologue about programming ( "actually..." :-D ) I started to investigate the Unit commit bug that I have found and just avoided during the JDBC connector development.

I initially thought that the problem is caused by trying to save a Message entity and the refresh problems on the GUI. After replicating the error, I tested this assumption and found it wrong: saving a single Tag entity into a new unit also failed. I investigated the content of the JSON and found that the problematic attribute is within the Unit entity itself, the NextId attribute value was saved but the reference to the attribute definition was missing. Tested by manually adding the reference to JSON, found it successful.

As the error was found, I tried to give the simplest fix: for a new unit without nextId, not only return the initial 0 value, but also set it in the entity. It solved the problem. After a successful reload, also added a temporal debug breakpoint to see how it runs. Convinced myself that the bug is fixed. Happy, happy!

Takeaways
 - start the debugging with an initial assumption (not just trial and error)
 - test the assumption first (in this case I was wrong, drill down to the simplest test case)
 - continue with the simplest case and investigate actual data (use human readable formats whenever possible, it saves you ages in bugfixing! This is why I use JSON)
 - try to give the simplest fix and use existing mechanisms instead of being smart on the spot
 - test the fix both using the test cases and with breakpoints to see that the change is called and the mechanism does what you assumed (if the data structure is complicated, create nice toString()-s, the IDE will show that and will save you tons of time again)