Skip to content

fix: replace bare except Exception with proper error logging#6307

Closed
MD-Mushfiqur123 wants to merge 1 commit into
avocado-framework:masterfrom
MD-Mushfiqur123:master
Closed

fix: replace bare except Exception with proper error logging#6307
MD-Mushfiqur123 wants to merge 1 commit into
avocado-framework:masterfrom
MD-Mushfiqur123:master

Conversation

@MD-Mushfiqur123
Copy link
Copy Markdown

@MD-Mushfiqur123 MD-Mushfiqur123 commented May 28, 2026

Closing - the affected utils have been migrated to AAutils project.

@mr-avocado mr-avocado Bot moved this to Review Requested in Default project May 28, 2026
@mr-avocado
Copy link
Copy Markdown

mr-avocado Bot commented May 28, 2026

You are changing one of the avocado utils which has already been migrated to AAutils project https://github.com/avocado-framework/aautils and this utility will be removed after the LTS release. Please make sure that all your proposed changes are already in AAutils and this PR is only backport.

For more information about AAutlis migration see https://avocado-framework.readthedocs.io/en/latest/blueprints/BP005.html

For a list of migrated utilities see https://avocado-framework.github.io/aautils.html

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces silent exception handling (bare except: pass blocks) with logging statements across several modules, including teststmpdir.py, filelock.py, and genio.py. The review feedback recommends preserving exception details by adding exc_info=True to the logging calls. Additionally, it is suggested to change the log level from WARNING to DEBUG in genio.py to avoid polluting the logs with false-positive warnings when files are expectedly missing.

Comment on lines +49 to +50
LOG.warning("Failed to remove temporary directory '%s'",
self._dirname)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When replacing a bare except: pass with logging, it is highly recommended to preserve the exception details (such as the traceback and error message) by passing exc_info=True. Without this, troubleshooting why the temporary directory could not be removed (e.g., permission issues, directory not empty, etc.) remains difficult.

Suggested change
LOG.warning("Failed to remove temporary directory '%s'",
self._dirname)
LOG.warning("Failed to remove temporary directory '%s'",
self._dirname, exc_info=True)

Comment thread avocado/utils/filelock.py
Comment on lines +80 to +81
LOG.debug("Failed to read lock file '%s'",
self.filename)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similarly, when logging a failure to read the lock file at DEBUG level, including the exception traceback via exc_info=True is extremely helpful for diagnosing lock contention or permission issues during debugging.

Suggested change
LOG.debug("Failed to read lock file '%s'",
self.filename)
LOG.debug("Failed to read lock file '%s'",
self.filename, exc_info=True)

Comment thread avocado/utils/genio.py
contents = [line.rstrip("\n") for line in file_obj.readlines()]
except Exception: # pylint: disable=W0703
pass
LOG.warning("Failed to read file '%s'", filename)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the docstring of read_all_lines, this function is explicitly designed to return an empty list in any error scenario, and is intended to be used when a missing or unreadable file is an expected/acceptable condition. Logging a WARNING here will flood the logs with false-positive warnings during normal operation when files are expectedly missing. Changing this to LOG.debug with exc_info=True avoids log pollution while still preserving the ability to troubleshoot actual issues when debug logging is enabled.

Suggested change
LOG.warning("Failed to read file '%s'", filename)
LOG.debug("Failed to read file '%s'", filename, exc_info=True)

@MD-Mushfiqur123
Copy link
Copy Markdown
Author

I see these utils have been migrated to AAutils. Closing this PR.

@github-project-automation github-project-automation Bot moved this from Review Requested to Done 114 in Default project May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done 114

Development

Successfully merging this pull request may close these issues.

1 participant