Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pylint Exception logging #9077

Open
wants to merge 63 commits into
base: main
Choose a base branch
from
Open

Conversation

JessicaBell00
Copy link
Contributor

@JessicaBell00 JessicaBell00 commented Oct 1, 2024

Addresses issue #3227

MJoshuaB and others added 30 commits August 12, 2024 10:14
Merge azure-sdk-tools main into main
More testing still to come
Also added more test cases
Also added one test and link for python implementation
Edits to fix false positives from testing against SDKs. Added more unit tests
expression = j.as_string().lower()
if any(x in expression for x in levels_matches) and "logger" in expression:
# Check for variables after strings
end_finder = expression.rfind("'")
Copy link
Member

Choose a reason for hiding this comment

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

could you explain an example where the end_finder would be used? Would it always be a single quote string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added to help fix a false positive from testing against the SDKs. end_finder finds the end of any strings being logged which should give access to just the variables after. For the code example below, this should mean that the checker is triggered for the variable 'exception' rather than the usage of the word 'exception' in the string.
except Exception as exception:
logger.warning("There has been an exception", exception)
If there is only a string and no variables after, it should look at the string instead.
As for the single quote, when the checker looks at the string it seems to convert double quotes to single quotes. Think the culprit might be expression = j.as_string(). So while the above code uses double quotes, when my checker runs they switch to single. Happy to investigate this further if you'd like.

for i in range(len(expression1)):
if exception_name == expression1[i]:
if i+1 < len(expression1):
if "." and "name" not in expression1[i+1]:
Copy link
Member

Choose a reason for hiding this comment

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

Is this looking for if exception.__name__ is used? Are there any other cases here where we would not want to raise a pylint error? (if not sure we could add a #TODO comment for future investigating)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is looking for exception.__name__. Could make it more specific - e.g. change if "." and "name" not in expression1[i+1]: to if ".__name__" not in expression1[i+1]: if you think that would be better.
As for other cases, didn't find any while testing against the SDKs, but can look into it further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants