ensure error conditions are indicated in the return value and prevent nullptr dereference in subsequent code.