Fix error reporting and nullpointers on invalid patterns