refactor: enhance error handling in user prompts
- Updated exception handling in multiple prompt functions to catch NotImplementedError alongside ImportError, improving robustness across the application. - Ensured fallback mechanisms are clearly documented for better understanding of platform limitations.
This commit is contained in:
parent
cd66546e24
commit
3c5bf5b9d8
4 changed files with 8 additions and 8 deletions
|
|
@ -923,7 +923,7 @@ def _prompt_model_selection(model_ids: List[str], current_model: str = "") -> Op
|
||||||
custom = input("Enter model name: ").strip()
|
custom = input("Enter model name: ").strip()
|
||||||
return custom if custom else None
|
return custom if custom else None
|
||||||
return None
|
return None
|
||||||
except ImportError:
|
except (ImportError, NotImplementedError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Fallback: numbered list
|
# Fallback: numbered list
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ def _prompt_provider_choice(choices):
|
||||||
idx = menu.show()
|
idx = menu.show()
|
||||||
print()
|
print()
|
||||||
return idx
|
return idx
|
||||||
except ImportError:
|
except (ImportError, NotImplementedError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Fallback: numbered list
|
# Fallback: numbered list
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,8 @@ def prompt_choice(question: str, choices: list, default: int = 0) -> int:
|
||||||
print() # Add newline after selection
|
print() # Add newline after selection
|
||||||
return idx
|
return idx
|
||||||
|
|
||||||
except ImportError:
|
except (ImportError, NotImplementedError):
|
||||||
# Fallback to number-based selection
|
# Fallback to number-based selection (simple_term_menu doesn't support Windows)
|
||||||
for i, choice in enumerate(choices):
|
for i, choice in enumerate(choices):
|
||||||
marker = "●" if i == default else "○"
|
marker = "●" if i == default else "○"
|
||||||
if i == default:
|
if i == default:
|
||||||
|
|
@ -192,8 +192,8 @@ def prompt_checklist(title: str, items: list, pre_selected: list = None) -> list
|
||||||
selected = list(terminal_menu.chosen_menu_indices or [])
|
selected = list(terminal_menu.chosen_menu_indices or [])
|
||||||
return selected
|
return selected
|
||||||
|
|
||||||
except ImportError:
|
except (ImportError, NotImplementedError):
|
||||||
# Fallback: numbered toggle interface
|
# Fallback: numbered toggle interface (simple_term_menu doesn't support Windows)
|
||||||
selected = set(pre_selected)
|
selected = set(pre_selected)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ def _prompt_choice(question: str, choices: list, default: int = 0) -> int:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
print()
|
print()
|
||||||
return idx
|
return idx
|
||||||
except ImportError:
|
except (ImportError, NotImplementedError):
|
||||||
for i, c in enumerate(choices):
|
for i, c in enumerate(choices):
|
||||||
marker = "●" if i == default else "○"
|
marker = "●" if i == default else "○"
|
||||||
style = Colors.GREEN if i == default else ""
|
style = Colors.GREEN if i == default else ""
|
||||||
|
|
@ -179,7 +179,7 @@ def _prompt_toolset_checklist(platform_label: str, enabled: Set[str]) -> Set[str
|
||||||
|
|
||||||
return {CONFIGURABLE_TOOLSETS[i][0] for i in selected_indices}
|
return {CONFIGURABLE_TOOLSETS[i][0] for i in selected_indices}
|
||||||
|
|
||||||
except ImportError:
|
except (ImportError, NotImplementedError):
|
||||||
# Fallback: numbered toggle
|
# Fallback: numbered toggle
|
||||||
selected = set(pre_selected_indices)
|
selected = set(pre_selected_indices)
|
||||||
while True:
|
while True:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue