Return error instead of panic