Pass back errors properly

We never set ret, so just copy back to ret if an error occurs