Easy error reproduction. Insert a default Icosphere and then, with it selected, run the script. (turns out it was because I was trying to create <3 point faces. This error state should be handled more elegantly.)