mesa: split error handling into its own file