Skip to content

Commit

Permalink
fix: Add global uncaught error handler to the main function
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmo00 committed Nov 19, 2023
1 parent edb1a50 commit 11c524f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 41 deletions.
87 changes: 46 additions & 41 deletions alxcheck/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,56 @@


def main():
if not check_file_present("README.md"):
print_file_not_present("README.md")
sys.exit(1)
if not check_file_not_empty("README.md"):
print_file_empty("README.md")
for root, dirs, files in os.walk("."):
# exclude virtual environment folders
for dir in dirs:
if is_python_virtual_env_folder(dir):
dirs.remove(dir)
break
# exclude .git folder
if ".git" in dirs:
dirs.remove(".git")
for file in files:
file_path = os.path.join(root, file)
if file_path.endswith(
(".c", ".py", ".js", ".m", ".h", ".mjs", ".jsx", ".json")
):
if not check_file_ends_with_new_line(file_path):
if not is_empty_init_py(file_path):
print_no_ending_new_line(file_path)
# c and c header files
if file.endswith((".c", ".h")):
betty_check(file_path)
# python checks
if file_path.endswith(".py") and not is_empty_init_py(file_path):
if not check_file_is_executable(file_path):
print_file_not_executable(file_path)
if not is_empty_init_py(file_path) and not check_python_shebang(
file_path
try:
if not check_file_present("README.md"):
print_file_not_present("README.md")
sys.exit(1)
if not check_file_not_empty("README.md"):
print_file_empty("README.md")
for root, dirs, files in os.walk("."):
# exclude virtual environment folders
for dir in dirs:
if is_python_virtual_env_folder(dir):
dirs.remove(dir)
break
# exclude .git folder
if ".git" in dirs:
dirs.remove(".git")
for file in files:
file_path = os.path.join(root, file)
if file_path.endswith(
(".c", ".py", ".js", ".m", ".h", ".mjs", ".jsx", ".json")
):
print_no_shebang(file_path)
check_module_function_class_documentation(file_path)
pycodestyle_check(file_path)
# javascript checks
if file.endswith(".js"):
if is_nodejs_project():
if not check_file_ends_with_new_line(file_path):
if not is_empty_init_py(file_path):
print_no_ending_new_line(file_path)
# c and c header files
if file.endswith((".c", ".h")):
betty_check(file_path)
# python checks
if file_path.endswith(".py") and not is_empty_init_py(file_path):
if not check_file_is_executable(file_path):
print_file_not_executable(file_path)
if not check_javascript_shebang(file_path):
if not is_empty_init_py(file_path) and not check_python_shebang(
file_path
):
print_no_shebang(file_path)
if not check_no_var(file_path):
print_var_was_used(file_path)
semistandard_check(file_path)
check_module_function_class_documentation(file_path)
pycodestyle_check(file_path)
# javascript checks
if file.endswith(".js"):
if is_nodejs_project():
if not check_file_is_executable(file_path):
print_file_not_executable(file_path)
if not check_javascript_shebang(file_path):
print_no_shebang(file_path)
if not check_no_var(file_path):
print_var_was_used(file_path)
semistandard_check(file_path)
except Exception as e:
print_uncaught_exception()
sys.stderr = open("./error.txt", "w")
raise


if __name__ == "__main__":
Expand Down
8 changes: 8 additions & 0 deletions alxcheck/utils/error_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,11 @@ def print_error_parsing_file(file_path):
)
except Exception as e:
print(Fore.RED + f"Error Parsing File:\n\t{type(e)}" + Fore.RESET)


def print_uncaught_exception():
print(
Fore.YELLOW
+ "Uncaught Exception: Please raise and issue here with the contents of './error.txt'\n\thttps://github.com/Emmo00/alxcheck/issues"
+ Fore.RESET
)

0 comments on commit 11c524f

Please sign in to comment.