fix inspectcsv error handling

This fixes a reference before assignment, and the error handling code in inspectcsv.