Fix permission error detection