better error message for unexpected category, close #314