Skip to content

Commit

Permalink
fix formatting for assertions and add notes
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeptightAnsiC committed Mar 24, 2024
1 parent 6e7c3e4 commit 05bd9c7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
7 changes: 4 additions & 3 deletions ue4cli/JsonDataManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ def __init__(self, jsonFile):

def loads(self):
"""
Wrapper for json.loads which reads owned jsonFile and loads it
In case of encountering JSONDecodeError, it will raise UtilityException
Reads and loads owned jsonFile
"""
try:
path = self.jsonFile
file = Utility.readFile(path)
return json.loads(file)
except json.JSONDecodeError as e:
raise UtilityException(f'failed to load {str(path)} due to {type(e).__name__} {str(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)}')

def getKey(self, key):
"""
Expand Down
2 changes: 1 addition & 1 deletion ue4cli/UnrealManagerWindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def getGenerateScript(self):
except:
pass

raise UnrealManagerException('could not detect the location of GenerateProjectFiles.bat or UnrealVersionSelector.exe.\nThis typically indicates that .uproject files are not correctly associated with UE4.')
raise UnrealManagerException('could not detect the location of GenerateProjectFiles.bat or UnrealVersionSelector.exe. This typically indicates that .uproject files are not correctly associated with UE4.')

def getRunUATScript(self):
return self.getEngineRoot() + '\\Engine\\Build\\BatchFiles\\RunUAT.bat'
Expand Down
10 changes: 5 additions & 5 deletions ue4cli/Utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}')

@staticmethod
def writeFile(filename, data):
Expand All @@ -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)}')

@staticmethod
def moveFile(src, dst):
Expand All @@ -54,7 +54,7 @@ def moveFile(src, dst):
try:
shutil.move(src, dst)
except OSError as e:
raise UtilityException(f'failed to move {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)}')

@staticmethod
def patchFile(filename, replacements):
Expand All @@ -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)}')

@staticmethod
def makeDirs(name, mode=0o777, exist_ok=False):
Expand All @@ -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)}')

@staticmethod
def forwardSlashes(paths):
Expand Down
11 changes: 8 additions & 3 deletions ue4cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,10 @@ def displayHelp():
print()

def main():

logger = logging.getLogger(__name__)

try:
logger = logging.getLogger(__name__)

# Perform plugin detection and register our detected plugins
plugins = PluginManager.getPlugins()
for command in plugins:
Expand All @@ -224,14 +225,18 @@ def main():
if command in SUPPORTED_COMMANDS:
SUPPORTED_COMMANDS[command]['action'](manager, args)
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 + '"')

except (
UnrealManagerException,
UtilityException,
KeyboardInterrupt,
) as e:
Utility.printStderr('(' + type(e).__name__ + ')', str(e))
Utility.printStderr(f'Error: ({type(e).__name__}) {str(e)}')
sys.exit(1)

except BaseException as e:
Utility.printStderr('Unhandled exception! Crashing...')
logging.basicConfig(level=logging.DEBUG)
Expand Down

0 comments on commit 05bd9c7

Please sign in to comment.