If the dispatch fails at any point, we run again with unmet demand variables, and return an error message giving the commodities with unmet demand to help diagnose the problem. We also have a debug_unmet_demand.csv file, the purpose of which is to give more detailed data about the unmet demand in this situation (i.e. which timeslices, how much unmet demand).
BUT, this file never gets written to because we exit the program with the error message before calling the output file writer. Not sure when this crept in but I'm pretty sure this used to work fine.
I think we just have to reshuffle things so the output file writer gets called before exiting.