The R helper function that constructs the simulated source ref returns something in the shape of a source ref even in error cases, but you're right, this could be safer. I've added some checks to the place where the return value is used to ensure that we're working with a valid ref.