You might consider using stdlib's ensure_resource function here, but it's probably not strictly necessary.