From f755b593598b4b163aba28ecac42a52da44c0a78 Mon Sep 17 00:00:00 2001 From: Justin Ely Date: Fri, 14 May 2021 14:09:11 -0400 Subject: [PATCH] add defensive coding against None in pre-commit hook Signed-off-by: Justin Ely --- tools/code_format/check_format.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/code_format/check_format.py b/tools/code_format/check_format.py index c03697fec7aca..3e24b50f261a6 100755 --- a/tools/code_format/check_format.py +++ b/tools/code_format/check_format.py @@ -323,11 +323,15 @@ def read_file(self, path): # look_path searches for the given executable in all directories in PATH # environment variable. If it cannot be found, empty string is returned. def look_path(self, executable): + if executable is None: + return '' return shutil.which(executable) or '' # path_exists checks whether the given path exists. This function assumes that # the path is absolute and evaluates environment variables. def path_exists(self, executable): + if executable is None: + return False return os.path.exists(os.path.expandvars(executable)) # executable_by_others checks whether the given path has execute permission for