-
Notifications
You must be signed in to change notification settings - Fork 10
wraped in try except #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thank you for your contribution! :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves error handling for interactive prompts by wrapping various user input sections in try/except blocks to catch cancellation events.
- Added a top-level try block around the pod creation logic for API error handling.
- Introduced try/except blocks for GPU selection, provider selection, configuration selection, pod name, disk size, vCPU, memory, image, and team ID prompts.
- Wrapped the final pod creation confirmation to handle cancellation gracefully.
try: | ||
# Show available GPU types | ||
console.print("\n[bold]Available GPU Types:[/bold]") | ||
gpu_types = sorted( | ||
[ | ||
gpu_type | ||
for gpu_type, gpus in availabilities.items() | ||
if len(gpus) > 0 | ||
] | ||
) | ||
for idx, gpu_type_option in enumerate(gpu_types, 1): | ||
console.print(f"{idx}. {gpu_type_option}") | ||
|
||
gpu_type_idx = typer.prompt("Select GPU type number", type=int, default=1) | ||
if gpu_type_idx < 1 or gpu_type_idx > len(gpu_types): | ||
console.print("[red]Invalid GPU type selection[/red]") | ||
raise typer.Exit(1) | ||
gpu_type = gpu_types[gpu_type_idx - 1] | ||
gpu_type_idx = typer.prompt( | ||
"Select GPU type number", type=int, default=1 | ||
) | ||
if gpu_type_idx < 1 or gpu_type_idx > len(gpu_types): | ||
console.print("[red]Invalid GPU type selection[/red]") | ||
raise typer.Exit(1) | ||
gpu_type = gpu_types[gpu_type_idx - 1] | ||
except (KeyboardInterrupt, typer.Abort): | ||
console.print( | ||
"\n[yellow]GPU type selection cancelled by user[/yellow]" | ||
) | ||
raise typer.Exit(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple similar try/except blocks for handling interactive prompt cancellations are used throughout the function. Consider extracting a helper function for prompt interactions and cancellation to reduce duplicate code and improve maintainability.
Copilot uses AI. Check for mistakes.
fixes #34
i tried wrapping everything in try except for abort error handling if there is any better approach you think i should take please let me know : )