Skip to content

Commit

Permalink
Catch exception for edk2_pr_eval when PR file changes includes a dele…
Browse files Browse the repository at this point in the history
…ted directory (#202)

stuart_pr_eval raises exception on a PR where a folder was deleted when a platform supports DSC dependency detection (Policy 4).

* Catch exception if GetContainingModules raises one because the parent folder was deleted.
* Change exception handling for failed attempt to get containing package to report as warning instead of error since this is expected for file deletes.
  • Loading branch information
spbrogan authored Jun 12, 2020
1 parent e036937 commit 2505a53
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions edk2toolext/invocables/edk2_pr_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def get_packages_to_build(self, possible_packages: list) -> dict:
pkg = self.edk2_path_obj.GetContainingPackage(os.path.abspath(f))

except Exception as e:
self.logger.error(f"Failed to get package for file {f}. Exception {e}")
self.logger.warning(f"Failed to get package for file {f}. Exception {e}")
# Ignore a file in which we fail to get the package
continue

Expand All @@ -167,7 +167,7 @@ def get_packages_to_build(self, possible_packages: list) -> dict:
pkg = self.edk2_path_obj.GetContainingPackage(os.path.abspath(f))

except Exception as e:
self.logger.error(f"Failed to get package for file {f}. Exception {e}")
self.logger.warning(f"Failed to get package for file {f}. Exception {e}")
# Ignore a file in which we fail to get the package
continue

Expand Down Expand Up @@ -231,10 +231,16 @@ def _get_unique_module_infs_changed(self, files: list):
for f in files:
if os.path.splitext(f) in [".txt", ".md"]: # ignore markdown and txt files
continue
try:
infs = self.edk2_path_obj.GetContainingModules(os.path.abspath(f))
except Exception as e:
self.logger.warning(f"Failed to get module for file {f}. Exception: {str(e)}")
# ignore errors. These will occur if a module or last file in folder is deleted as part of the PR
continue

infs = self.edk2_path_obj.GetContainingModules(os.path.abspath(f))
if len(infs) > 0: # if this file is part of any INFs
modules.extend(infs)

modules = [self.edk2_path_obj.GetEdk2RelativePathFromAbsolutePath(x) for x in set(modules)]
logging.debug("Changed Modules: " + str(modules))
return modules
Expand Down Expand Up @@ -323,7 +329,7 @@ def _is_public_file(self, filepath):
try:
pkg = self.edk2_path_obj.GetContainingPackage(os.path.abspath(filepath))
except Exception as e:
self.logger.error(f"Failed to GetContainingPackage({filepath}). Exception: {str(e)}")
self.logger.warning(f"Failed to get package for {filepath}. Exception: {str(e)}")
return False

dec = None
Expand Down

0 comments on commit 2505a53

Please sign in to comment.