Catch SyntaxError from tokenizing for traceback

I don't think there's an easy way to test this, but I've verified the fix by hand.

Closes gh-6300