added custom exception for undefined env variables

cc // @pewniak747 @bartoszkopinski 
Use `fail` instead of `raise` to signal exceptions.