Refactor error handling for coverage