aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/generate
diff options
context:
space:
mode:
authorNick Brassel <[email protected]>2024-06-15 19:37:47 +1000
committerGitHub <[email protected]>2024-06-15 10:37:47 +0100
commit0262161914133e6abfc306e675dbac3ba816a6ee (patch)
tree042db91495759ceb4bc54895017a4420427d581d /lib/python/qmk/cli/generate
parentd4654ab8934f795bbfc294f5b128a94aaa645a78 (diff)
downloadqmk_firmware-0262161914133e6abfc306e675dbac3ba816a6ee.tar.gz
qmk_firmware-0262161914133e6abfc306e675dbac3ba816a6ee.zip
[CLI] Don't `exit()` when certain exceptions occur. (#23442)
Diffstat (limited to 'lib/python/qmk/cli/generate')
-rw-r--r--lib/python/qmk/cli/generate/autocorrect_data.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/python/qmk/cli/generate/autocorrect_data.py b/lib/python/qmk/cli/generate/autocorrect_data.py
index b11c66d95d..01a29b46fe 100644
--- a/lib/python/qmk/cli/generate/autocorrect_data.py
+++ b/lib/python/qmk/cli/generate/autocorrect_data.py
@@ -27,7 +27,6 @@ Example:
For full documentation, see QMK Docs
"""
-import sys
import textwrap
from typing import Any, Dict, Iterator, List, Tuple
@@ -38,6 +37,7 @@ from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.keymap import keymap_completer, locate_keymap
from qmk.path import normpath
+from qmk.util import maybe_exit
KC_A = 4
KC_SPC = 0x2c
@@ -88,16 +88,16 @@ def parse_file(file_name: str) -> List[Tuple[str, str]]:
# Check that `typo` is valid.
if not (all([c in TYPO_CHARS for c in typo])):
cli.log.error('{fg_red}Error:%d:{fg_reset} Typo "{fg_cyan}%s{fg_reset}" has characters other than a-z, \' and :.', line_number, typo)
- sys.exit(1)
+ maybe_exit(1)
for other_typo in typos:
if typo in other_typo or other_typo in typo:
cli.log.error('{fg_red}Error:%d:{fg_reset} Typos may not be substrings of one another, otherwise the longer typo would never trigger: "{fg_cyan}%s{fg_reset}" vs. "{fg_cyan}%s{fg_reset}".', line_number, typo, other_typo)
- sys.exit(1)
+ maybe_exit(1)
if len(typo) < 5:
cli.log.warning('{fg_yellow}Warning:%d:{fg_reset} It is suggested that typos are at least 5 characters long to avoid false triggers: "{fg_cyan}%s{fg_reset}"', line_number, typo)
if len(typo) > 127:
cli.log.error('{fg_red}Error:%d:{fg_reset} Typo exceeds 127 chars: "{fg_cyan}%s{fg_reset}"', line_number, typo)
- sys.exit(1)
+ maybe_exit(1)
check_typo_against_dictionary(typo, line_number, correct_words)
@@ -136,7 +136,7 @@ def parse_file_lines(file_name: str) -> Iterator[Tuple[int, str, str]]:
tokens = [token.strip() for token in line.split('->', 1)]
if len(tokens) != 2 or not tokens[0]:
print(f'Error:{line_number}: Invalid syntax: "{line}"')
- sys.exit(1)
+ maybe_exit(1)
typo, correction = tokens
typo = typo.lower() # Force typos to lowercase.
@@ -237,7 +237,7 @@ def encode_link(link: Dict[str, Any]) -> List[int]:
byte_offset = link['byte_offset']
if not (0 <= byte_offset <= 0xffff):
cli.log.error('{fg_red}Error:{fg_reset} The autocorrection table is too large, a node link exceeds 64KB limit. Try reducing the autocorrection dict to fewer entries.')
- sys.exit(1)
+ maybe_exit(1)
return [byte_offset & 255, byte_offset >> 8]