Improve error messages for generated tokens
Merge pull request #3319 from xixixao/issue1096

Fix 1096, 1131, 1828: Improve error messages for generated tokens