Improve error handling around null env vars

[Finishes #63319770]