Factor error reporting out into its own function.