Raise repo exit errors in place of sys.exit

Bug: b/293344017
Change-Id: I92d81c78eba8ff31b5252415f4c9a515a6c76411
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/381774
Tested-by: Jason Chang <jasonnc@google.com>
Reviewed-by: Joanna Wang <jojwang@google.com>
Commit-Queue: Jason Chang <jasonnc@google.com>
This commit is contained in:
Jason Chang
2023-08-03 14:38:00 -07:00
committed by LUCI
parent b8a7b4a629
commit f9aacd4087
9 changed files with 80 additions and 34 deletions

View File

@ -16,11 +16,11 @@ import multiprocessing
import os
import optparse
import re
import sys
from event_log import EventLog
from error import NoSuchProjectError
from error import InvalidProjectGroupsError
from error import RepoExitError
import progress
@ -42,6 +42,10 @@ WORKER_BATCH_SIZE = 32
DEFAULT_LOCAL_JOBS = min(os.cpu_count(), 8)
class UsageError(RepoExitError):
"""Exception thrown with invalid command usage."""
class Command(object):
"""Base class for any command line action in repo."""
@ -215,7 +219,7 @@ class Command(object):
def Usage(self):
"""Display usage and terminate."""
self.OptionParser.print_usage()
sys.exit(1)
raise UsageError()
def CommonValidateOptions(self, opt, args):
"""Validate common options."""