The same logic is already used in line 287 but I do agree some kind of sanity checking would be nice.