diff --git a/ue4cli/JsonDataManager.py b/ue4cli/JsonDataManager.py index 7e94238..049f762 100644 --- a/ue4cli/JsonDataManager.py +++ b/ue4cli/JsonDataManager.py @@ -25,7 +25,7 @@ def loads(self): except json.JSONDecodeError as e: # FIXME: This is the only place outside of Utility class where we use UtilityException. # Not worth to create new Exception class for only one single case, at least not now. - raise UtilityException(f'failed to load "{str(path)}" due to: ({type(e).__name__}) {str(e)}') + raise UtilityException(f'failed to load "{str(path)}" due to: ({type(e).__name__}) {str(e)}') from e def getKey(self, key): """ diff --git a/ue4cli/UnrealManagerBase.py b/ue4cli/UnrealManagerBase.py index 6c9d301..ff60e6a 100644 --- a/ue4cli/UnrealManagerBase.py +++ b/ue4cli/UnrealManagerBase.py @@ -52,7 +52,7 @@ def setEngineRootOverride(self, rootDir): try: self.getEngineVersion() except: - raise UnrealManagerException('the specified directory does not appear to contain a valid version of the Unreal Engine.') + raise UnrealManagerException('the specified directory does not appear to contain a valid version of the Unreal Engine.') from None def clearEngineRootOverride(self): """ @@ -96,7 +96,7 @@ def getEngineVersion(self, outputFormat = 'full'): # Verify that the requested output format is valid if outputFormat not in formats: - raise UnrealManagerException('unreconised version output format "{}"'.format(outputFormat)) + raise UnrealManagerException(f'unreconised version output format "{str(outputFormat)}"') return formats[outputFormat] @@ -176,7 +176,7 @@ def getDescriptor(self, dir): try: return self.getPluginDescriptor(dir) except: - raise UnrealManagerException('could not detect an Unreal project or plugin in the directory "{}"'.format(dir)) + raise UnrealManagerException(f'could not detect an Unreal project or plugin in the directory "{str(dir)}"') from None def isProject(self, descriptor): """ @@ -355,11 +355,11 @@ def buildDescriptor(self, dir=os.getcwd(), configuration='Development', target=' # If the project or plugin is Blueprint-only, there is no C++ code to build if os.path.exists(os.path.join(dir, 'Source')) == False: - raise UnrealManagerException('Pure Blueprint {}, nothing to build.'.format(descriptorType)) + raise UnrealManagerException(f'Pure Blueprint {str(descriptorType)}, nothing to build.') # Verify that the specified build configuration is valid if configuration not in self.validBuildConfigurations(): - raise UnrealManagerException('invalid build configuration "' + configuration + '"') + raise UnrealManagerException(f'invalid build configuration "{str(configuration)}"') # Check if the user specified the `-notools` flag to opt out of building Engine tools when working with source builds unstripped = list(args) @@ -408,7 +408,7 @@ def packageProject(self, dir=os.getcwd(), configuration='Shipping', extraArgs=[] # Verify that the specified build configuration is valid if configuration not in self.validBuildConfigurations(): - raise UnrealManagerException('invalid build configuration "' + configuration + '"') + raise UnrealManagerException(f'invalid build configuration "{str(configuration)}"') # Strip out the `-NoCompileEditor` flag if the user has specified it, since the Development version # of the Editor modules for the project are needed in order to run the commandlet that cooks content @@ -538,10 +538,12 @@ def listAutomationTests(self, projectFile): # Detect if the Editor terminated abnormally (i.e. not triggered by `automation quit`) # In Unreal Engine 4.27.0, the exit method changed from RequestExit to RequestExitWithStatus if 'PlatformMisc::RequestExit(' not in logOutput.stdout and 'PlatformMisc::RequestExitWithStatus(' not in logOutput.stdout: - raise UnrealManagerException( - 'failed to retrieve the list of automation tests!' + - ' stdout was: "{}", stderr was: "{}"'.format(logOutput.stdout, logOutput.stderr) - ) + Utility.printStderr("Warning: abnormal Editor termination detected!") + Utility.printStderr("printing stdout..") + print(logOutput.stdout) + Utility.printStderr("printing stderr..") + print(logOutput.stderr) + raise UnrealManagerException('failed to retrieve the list of automation tests!') return sorted(list(tests)) diff --git a/ue4cli/Utility.py b/ue4cli/Utility.py index 7d7a8ff..d8989da 100644 --- a/ue4cli/Utility.py +++ b/ue4cli/Utility.py @@ -33,7 +33,7 @@ def readFile(filename): with open(filename, 'rb') as f: return f.read().decode('utf-8') except OSError as e: - raise UtilityException(f'failed to read file "{str(filename)}" due to: ({type(e).__name__}) {str(e)}') + raise UtilityException(f'failed to read file "{str(filename)}" due to: ({type(e).__name__}) {str(e)}') from e @staticmethod def writeFile(filename, data): @@ -44,7 +44,7 @@ def writeFile(filename, data): with open(filename, 'wb') as f: f.write(data.encode('utf-8')) except OSError as e: - raise UtilityException(f'failed to write file "{str(filename)}" due to: ({type(e).__name__}) {str(e)}') + raise UtilityException(f'failed to write file "{str(filename)}" due to: ({type(e).__name__}) {str(e)}') from e @staticmethod def moveFile(src, dst): @@ -54,7 +54,7 @@ def moveFile(src, dst): try: shutil.move(src, dst) except OSError as e: - raise UtilityException(f'failed to move file from "{str(src)}" to "{str(dst)}" due to: ({type(e).__name__}) {str(e)}') + raise UtilityException(f'failed to move file from "{str(src)}" to "{str(dst)}" due to: ({type(e).__name__}) {str(e)}') from e @staticmethod def patchFile(filename, replacements): @@ -77,7 +77,7 @@ def removeDir(path, ignore_errors=False): try: shutil.rmtree(path, ignore_errors) except OSError as e: - raise UtilityException(f'failed to remove directory "{str(path)}" due to: ({type(e).__name__}) {str(e)}') + raise UtilityException(f'failed to remove directory "{str(path)}" due to: ({type(e).__name__}) {str(e)}') from e @staticmethod def makeDirs(name, mode=0o777, exist_ok=False): @@ -87,7 +87,7 @@ def makeDirs(name, mode=0o777, exist_ok=False): try: os.makedirs(name, mode, exist_ok) except OSError as e: - raise UtilityException(f'failed to create directory "{str(name)}" due to: ({type(e).__name__}) {str(e)}') + raise UtilityException(f'failed to create directory "{str(name)}" due to: ({type(e).__name__}) {str(e)}') from e @staticmethod def forwardSlashes(paths): diff --git a/ue4cli/cli.py b/ue4cli/cli.py index a66fe35..df88040 100644 --- a/ue4cli/cli.py +++ b/ue4cli/cli.py @@ -227,7 +227,7 @@ def main(): else: # FIXME: This is the only place outside of UnrealManager... classes where we use UnrealManagerException. # Not worth to create new Exception class for only one single case, at least not now. - raise UnrealManagerException('unrecognised command "' + command + '"') + raise UnrealManagerException(f'unrecognised command "{str(command)}"') from None except ( UnrealManagerException,