Could you print a diagnostic here and in the other failure cases? It applies also to other functions that have multiple reasons to fail.

When developing, it saves one "compilation roundtrip" to figure out which error case happened. When being tested by QA, it will make the bug report more helpful.