-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add placeholders * add new placeholder comments * exploring AST unfinished - minor emergency had to leave * identifying some mismatched functions * refactor checker and tests * fix error with non-builtins decorators * fine tuning and testing required * add pylint report * add ranked listing of reports * format report as table * add new verbs * update report * update reportcounts.md * fix formatting for reportcounts.md * update reportcounts.md * minimal tests added * Base code and unit tests More testing still to come * Refactored class to be more specific Also added more test cases * Added to README Also added one test and link for python implementation * Update README / fix merging * Final Refactor * Fixed false positives Edits to fix false positives from testing against SDKs. Added more unit tests * not running multiple times picking up on different function types * add TODOs * removed code not reached * Checks at a class level * Looking into different connection_verify assignments * Placeholders added back * Checker base done * exclue private namespaces and classes * update reports * Checker, Tests, & Readme done * Update pylint_guidelines_checker.py Fix another false positive from the SDKs * Fix another false positive Added corresponding test * Check either sides of indices Fixed another false positive * add new prefixes * update unit tests * remove reports * remove commented code * add checker to README * Tidy Up * Add TODO comment re other cases to investigate * Revert "Merge branch 'working-main' into exception-logging" This reverts commit e2dcbb9, reversing changes made to 7e7256b. * Make checker more explicit Switch "." and "name" to ".__name__" --------- Co-authored-by: Joshua Bishop <[email protected]> Co-authored-by: Alirose Burrell <[email protected]> Co-authored-by: 16234397 <[email protected]>
- Loading branch information
1 parent
4807474
commit 88c86a6
Showing
4 changed files
with
363 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...lint-extensions/azure-pylint-guidelines-checker/tests/test_files/do_not_log_exceptions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from plugin import logger | ||
|
||
|
||
# test_logging_levels_logged_str_exception | ||
def test_logging_levels_logged_str_exception(): | ||
try: # @ | ||
add = 1 + 2 | ||
except Exception as ex: | ||
logger.error("Error" + str(ex)) # @ | ||
logger.warning(str(ex)) | ||
logger.info(str(ex)) | ||
logger.debug(str(ex)) | ||
|
||
|
||
# test_logging_levels_logged_repr_exception | ||
def test_logging_levels_logged_repr_exception(): | ||
try: # @ | ||
add = 1 + 2 | ||
except Exception as ex: | ||
logger.error(repr(ex)) # @ | ||
logger.warning(repr(ex)) | ||
logger.info(repr(ex)) | ||
logger.debug(repr(ex)) | ||
|
||
|
||
# test_regular_logging_ok | ||
def test_regular_logging_ok(): | ||
try: # @ | ||
add = 1 + 2 | ||
except Exception as ex: | ||
logger.error("Example 1") # @ | ||
logger.warning("This is another example") | ||
logger.info("Random logging") | ||
logger.debug("Logging") | ||
|
||
|
||
# test_logging_str_exception_branches | ||
def test_logging_str_exception_branches(): | ||
try: # @ | ||
add = 1 + 2 | ||
except Exception as ex: | ||
if ex.code == "Retryable": | ||
logger.error(str(ex)) | ||
return True | ||
elif Exception != BaseException: | ||
logger.warning(repr(ex)) | ||
return False | ||
else: | ||
logger.info(str(ex)) # @ | ||
|
||
|
||
# test_other_logging_fails | ||
def test_other_logging_fails(): | ||
try: # @ | ||
add = 1 + 2 | ||
except Exception as ex: | ||
if ex.code == "Retryable": | ||
logger.error("Something went wrong: {ex}. Try again") | ||
return True | ||
else: | ||
logger.warning(ex) | ||
return False | ||
|
||
|
||
# test_no_logging_and_no_exception_name_ok | ||
def test_no_logging_and_no_exception_name_ok(): | ||
try: | ||
add = 1 + 2 | ||
except Exception as ex: | ||
self.errors.appendleft(ex) | ||
except Exception as ex: # pylint: disable=broad-except | ||
_logger.warning( | ||
"Exception occurred when instrumenting: %s.", | ||
lib_name, | ||
exc_info=ex, | ||
) | ||
except (OSError, PermissionError) as e: | ||
logger.warning( | ||
"Failed to read on-disk cache for component due to %s. " | ||
"Please check if the file %s is in use or current user doesn't have the permission.", | ||
type(e).__name__, | ||
on_disk_cache_path.as_posix(), | ||
) | ||
|
||
|
||
# test_logging_without_exception_name | ||
def test_logging_without_exception_name(): | ||
try: | ||
add = 1 + 2 | ||
except Exception as exception: | ||
if exception.code == "Retryable": | ||
_LOGGER.info( | ||
"%r returns an exception %r", self._container_id, last_exception | ||
) | ||
else: | ||
module_logger.debug("Skipping file upload, reason: %s", str(e.reason)) |
Oops, something went wrong.