You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor: Standardize error reporting for argument failures
- Removes `parser.print_help()` calls from all error exit paths related to missing or invalid script arguments.
- Appends a consistent ' (use --help for more details)' note to these error messages.
- This provides more concise error output while still guiding the user to help if needed.
- Affects errors for token, URL, owner/repo specification, and PR number determination.
if (is_owner_from_useroris_repo_from_user): # User explicitly set at least one
312
+
ifargs.ownerandargs.repo: # Both were set (either explicitly or one explicit, one default that existed)
313
+
final_owner=args.owner
314
+
final_repo=args.repo
315
+
sys.stderr.write(f"Using repository from --owner/--repo args: {final_owner}/{final_repo}\n")
316
+
else: # User set one but not the other, and the other wasn't available from a default
317
+
sys.stderr.write(f"Error: Both --owner and --repo must be specified if one is provided explicitly (and --url is not used).{error_suffix}\n")
318
+
sys.exit(1)
319
+
elifargs.ownerandargs.repo: # Both are from successful auto-detection (already printed "Determined repository...")
320
+
final_owner=args.owner
321
+
final_repo=args.repo
322
+
elifargs.ownerorargs.repo: # Only one was available (e.g. auto-detect only found one, or bad default state)
323
+
sys.stderr.write(f"Error: Both --owner and --repo are required if not using --url, and auto-detection was incomplete.{error_suffix}\n")
306
324
sys.exit(1)
307
-
final_owner=args.owner
308
-
final_repo=args.repo
309
-
sys.stderr.write(f"Using repository from --owner/--repo args: {final_owner}/{final_repo}\n")
310
-
elifargs.ownerandargs.repo: # Using auto-detected values which are now in args.owner and args.repo
311
-
final_owner=args.owner
312
-
final_repo=args.repo
313
-
# The "Determined repository..." message was already printed if successful.
314
-
else: # Handles cases like only one of owner/repo being set after defaults, or auto-detection failed and nothing/partial was given.
315
-
if (args.ownerandnotargs.repo) or (notargs.ownerandargs.repo):
316
-
sys.stderr.write("Error: Both --owner and --repo must be specified if one is provided (and --url is not used).\n")
317
-
parser.print_help()
318
-
sys.exit(1)
319
-
# If it reaches here and final_owner/repo are still None, it means auto-detection failed and user didn't provide valid pair.
325
+
# If none of the above, final_owner/repo remain None, will be caught by the check below.
320
326
321
327
ifnotfinal_ownerornotfinal_repo:
322
-
sys.stderr.write("Error: Could not determine repository. Please specify --url, OR both --owner and --repo, OR ensure git remote 'origin' is configured correctly.\n")
323
-
sys.exit(1) # No print_help() here, as per request
328
+
sys.stderr.write(f"Error: Could not determine repository. Please specify --url, OR both --owner and --repo, OR ensure git remote 'origin' is configured correctly.{error_suffix}\n")
329
+
sys.exit(1)
330
+
331
+
332
+
ifnotfinal_ownerornotfinal_repo:
333
+
sys.stderr.write(f"Error: Could not determine repository. Please specify --url, OR both --owner and --repo, OR ensure git remote 'origin' is configured correctly.{error_suffix}\n")
334
+
sys.exit(1)
324
335
325
336
ifnotset_repo_url_standalone(final_owner, final_repo): # Sets global OWNER and REPO
326
-
sys.stderr.write(f"Error: Could not set repository to {final_owner}/{final_repo}. Ensure owner/repo are correct.\n")
337
+
sys.stderr.write(f"Error: Could not set repository to {final_owner}/{final_repo}. Ensure owner/repo are correct.{error_suffix}\n")
0 commit comments