Auto_Jobs_Applier_AI_Agent by AIHawk is an AI Agent that automates the jobs application process. Utilizing artificial intelligence, it enables users to apply for multiple jobs in an automated and personalized way.
GNU Affero General Public License v3.0
22.53k
stars
3.34k
forks
source link
[FEATURE]: Fix error handling and stop using unnecessary exceptions #819
Exceptions should be reserved for truly exceptional cases. There are many occurrences of exception abuse, overusing try-blocks, and excepting Exception when a function throws a specific exception.
Non-compliant
def _unfollow_company(self) -> None:
try:
logger.debug("Unfollowing company")
follow_checkbox = self.driver.find_element(
By.XPATH, "//label[contains(.,'to stay up to date with their page.')]")
follow_checkbox.click()
except Exception as e:
logger.debug(f"Failed to unfollow company: {e}")
Compliant
# compliant
def _unfollow_company(self) -> None:
logger.debug("Unfollowing company") # Does not throw exception - has no reason to be in the try-block
# Handle one function that throws an error at a time
try:
# find_element() only throws a NoSuchElementException - there's no reason to catch a general exception
follow_checkbox = self.driver.find_element(By.XPATH, "//label[contains(.,'to stay up to date with their page.')]")
except NoSuchElementException as e:
logger.debug(f"Failed to unfollow company: {e}")
# Does not throw exception - has no reason to be in the try-block
follow_checkbox.click()
Motivation
It significantly improves maintainability and readability
Alternatives considered
No, the current approach to error handling and exception abuse as flow control is unacceptable.
Feature summary
Exceptions are not meant for flow control
Feature description
Exceptions should be reserved for truly exceptional cases. There are many occurrences of exception abuse, overusing try-blocks, and excepting Exception when a function throws a specific exception.
Non-compliant
Compliant
Motivation
It significantly improves maintainability and readability
Alternatives considered
No, the current approach to error handling and exception abuse as flow control is unacceptable.
Additional context
No response