Also enhances the error message a bit, fixes #30505 on the way, and adds a test (which was missing). Closes #34018