I realized that I was trying to write data to the wrong table, so that's probably why the lastError was undefined. Sometimes, the answer is so simple... My bad!