Replace any use of ValueError with TypeError where it's reasonable