Fix #1: more robust error reporting