Fixes exception when getValue() returns an error.

Exception was being thrown about accessing properties on a null object instead of returning the proper error. I fixed this and added a test for it as well.