Better error handling in cookie lib