def main(): metrics.Started(START_TIME) # TODO(user): Put a real version number here metrics.Executions( 'gcloud', local_state.InstallationState.VersionForInstalledComponent('core')) _cli.Execute()
def main(gcloud_cli=None): metrics.Started(START_TIME) # TODO(b/36049857): Put a real version number here metrics.Executions( 'gcloud', local_state.InstallationState.VersionForInstalledComponent('core')) if gcloud_cli is None: gcloud_cli = CreateCLI([]) try: try: gcloud_cli.Execute() except IOError as err: # We want to ignore EPIPE IOErrors. # By default, Python ignores SIGPIPE (see # http://utcc.utoronto.ca/~cks/space/blog/python/SignalExceptionSurprise). # This means that attempting to write any output to a closed pipe (e.g. in # the case of output piped to `head` or `grep -q`) will result in an # IOError, which gets reported as a gcloud crash. We don't want this # behavior, so we ignore EPIPE (it's not a real error; it's a normal thing # to occur). # Before, we restore the SIGPIPE signal handler, but that caused issues # with scripts/programs that wrapped gcloud. if err.errno != errno.EPIPE: raise except Exception as err: # pylint:disable=broad-except crash_handling.HandleGcloudCrash(err) if properties.VALUES.core.print_unhandled_tracebacks.GetBool(): # We want to see the traceback as normally handled by Python raise else: # This is the case for most non-Cloud SDK developers. They shouldn't see # the full stack trace, but just the nice "gcloud crashed" message. sys.exit(1)
def main(gcloud_cli=None, credential_providers=None): atexit.register(metrics.Shutdown) if not platforms.PythonVersion().IsCompatible(): sys.exit(1) metrics.Started(START_TIME) metrics.Executions( 'gcloud', local_state.InstallationState.VersionForInstalledComponent('core')) if gcloud_cli is None: gcloud_cli = CreateCLI([]) with creds_context_managers.CredentialProvidersManager( credential_providers): try: gcloud_cli.Execute() # Flush stdout so that if we've received a SIGPIPE we handle the broken # pipe within this try block, instead of potentially during interpreter # shutdown. sys.stdout.flush() except IOError as err: # We want to ignore EPIPE IOErrors (as of Python 3.3 these can be caught # specifically with BrokenPipeError, but we do it this way for Python 2 # compatibility). # # By default, Python ignores SIGPIPE (see # http://utcc.utoronto.ca/~cks/space/blog/python/SignalExceptionSurprise # ). # This means that attempting to write any output to a closed pipe (e.g. # in the case of output piped to `head` or `grep -q`) will result in an # IOError, which gets reported as a gcloud crash. We don't want this # behavior, so we ignore EPIPE (it's not a real error; it's a normal # thing to occur). # # Before, we restored the SIGPIPE signal handler, but that caused issues # with scripts/programs that wrapped gcloud. if err.errno == errno.EPIPE: # At this point we've caught the broken pipe, but since Python flushes # standard streams on exit, it's still possible for a broken pipe # error to happen during interpreter shutdown. The interpreter will # catch this but in Python 3 it still prints a warning to stderr # saying that the exception was ignored # (see https://bugs.python.org/issue11380): # # Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' # encoding='UTF-8'> # BrokenPipeError: [Errno 32] Broken pipe # # To prevent this from happening, we redirect any remaining output to # devnull as recommended here: # https://docs.python.org/3/library/signal.html#note-on-sigpipe. devnull = os.open(os.devnull, os.O_WRONLY) os.dup2(devnull, sys.stdout.fileno()) else: raise
def main(): metrics.Started(START_TIME) # TODO(user): Put a real version number here metrics.Executions( 'gcloud', local_state.InstallationState.VersionForInstalledComponent('core')) try: _cli.Execute() except Exception as err: # pylint:disable=broad-except if isinstance(err, KeyboardInterrupt): raise traceback.print_exc() sys.exit(1)
def main(gcloud_cli=None, credential_providers=None): if not platforms.PythonVersion().IsCompatible( allow_py3=properties.VALUES.core.allow_py3.GetBool()): sys.exit(1) metrics.Started(START_TIME) # TODO(b/36049857): Put a real version number here metrics.Executions( 'gcloud', local_state.InstallationState.VersionForInstalledComponent('core')) if gcloud_cli is None: gcloud_cli = CreateCLI([]) # Register some other sources for credentials and project. credential_providers = credential_providers or [ creds_store.DevShellCredentialProvider(), creds_store.GceCredentialProvider(), ] for provider in credential_providers: provider.Register() # Register support for service account impersonation. creds_store.IMPERSONATION_TOKEN_PROVIDER = ( iamcred_util.ImpersonationAccessTokenProvider()) try: try: gcloud_cli.Execute() except IOError as err: # We want to ignore EPIPE IOErrors. # By default, Python ignores SIGPIPE (see # http://utcc.utoronto.ca/~cks/space/blog/python/SignalExceptionSurprise). # This means that attempting to write any output to a closed pipe (e.g. in # the case of output piped to `head` or `grep -q`) will result in an # IOError, which gets reported as a gcloud crash. We don't want this # behavior, so we ignore EPIPE (it's not a real error; it's a normal thing # to occur). # Before, we restore the SIGPIPE signal handler, but that caused issues # with scripts/programs that wrapped gcloud. if err.errno != errno.EPIPE: raise except Exception as err: # pylint:disable=broad-except crash_handling.HandleGcloudCrash(err) if properties.VALUES.core.print_unhandled_tracebacks.GetBool(): # We want to see the traceback as normally handled by Python raise else: # This is the case for most non-Cloud SDK developers. They shouldn't see # the full stack trace, but just the nice "gcloud crashed" message. sys.exit(1) finally: for provider in credential_providers: provider.UnRegister()
def main(): metrics.Started(START_TIME) # TODO(user): Put a real version number here metrics.Executions( 'gcloud', local_state.InstallationState.VersionForInstalledComponent('core')) try: _cli.Execute() except Exception as e: # pylint:disable=broad-except log.err.Print('Traceback (most recent call last):') unused_ex_type, unused_ex, tb = sys.exc_info() traceback.print_tb(tb, file=log.err) log.err.Print(type(e).__name__ + ': ' + _cli.SafeExceptionToString(e)) log.err.Print('\nIf you would like to report this issue, please run the ' 'following command:') log.err.Print(' gcloud feedback') sys.exit(1)
def main(gcloud_cli=None): metrics.Started(START_TIME) # TODO(user): Put a real version number here metrics.Executions( 'gcloud', local_state.InstallationState.VersionForInstalledComponent('core')) if gcloud_cli is None: gcloud_cli = CreateCLI([]) try: gcloud_cli.Execute() except Exception as err: # pylint:disable=broad-except # We want this to be parsable by `gcloud feedback`, so we print the # stacktrace with a nice recognizable string log.file_only_logger.exception('BEGIN CRASH STACKTRACE') _PrintSuggestedAction(err, gcloud_cli.SafeExceptionToString(err)) if properties.VALUES.core.print_unhandled_tracebacks.GetBool(): # We want to see the traceback as normally handled by Python raise else: # This is the case for most non-Cloud SDK developers. They shouldn't see # the full stack trace, but just the nice "gcloud crashed" message. sys.exit(1)
def main(): metrics.Started(START_TIME) # TODO(user): Put a real version number here metrics.Executions( 'gcloud', local_state.InstallationState.VersionForInstalledComponent('core')) try: _cli.Execute() except Exception as e: # pylint:disable=broad-except log.error('gcloud crashed ({0}): {1}'.format( getattr(e, 'error_name', type(e).__name__), _cli.SafeExceptionToString(e))) log.err.Print('\nIf you would like to report this issue, please run the ' 'following command:') log.err.Print(' gcloud feedback') if properties.VALUES.core.print_unhandled_tracebacks.GetBool(): # We want to see the traceback as normally handled by Python raise else: # This is the case for most non-Cloud SDK developers. They shouldn't see # the full stack trace, but just the nice "gcloud crashed" message. sys.exit(1)
def main(gcloud_cli=None, credential_providers=None): if not platforms.PythonVersion().IsCompatible( allow_py3=properties.VALUES.core.allow_py3.GetBool()): sys.exit(1) metrics.Started(START_TIME) # TODO(b/36049857): Put a real version number here metrics.Executions( 'gcloud', local_state.InstallationState.VersionForInstalledComponent('core')) if gcloud_cli is None: gcloud_cli = CreateCLI([]) # Register some other sources for credentials and project. credential_providers = credential_providers or [ creds_store.DevShellCredentialProvider(), creds_store.GceCredentialProvider(), ] for provider in credential_providers: provider.Register() # Register support for service account impersonation. creds_store.IMPERSONATION_TOKEN_PROVIDER = ( iamcred_util.ImpersonationAccessTokenProvider()) try: try: gcloud_cli.Execute() # Flush stdout so that if we've received a SIGPIPE we handle the broken # pipe within this try block, instead of potentially during interpreter # shutdown. sys.stdout.flush() except IOError as err: # We want to ignore EPIPE IOErrors (as of Python 3.3 these can be caught # specifically with BrokenPipeError, but we do it this way for Python 2 # compatibility). # # By default, Python ignores SIGPIPE (see # http://utcc.utoronto.ca/~cks/space/blog/python/SignalExceptionSurprise). # This means that attempting to write any output to a closed pipe (e.g. in # the case of output piped to `head` or `grep -q`) will result in an # IOError, which gets reported as a gcloud crash. We don't want this # behavior, so we ignore EPIPE (it's not a real error; it's a normal thing # to occur). # # Before, we restored the SIGPIPE signal handler, but that caused issues # with scripts/programs that wrapped gcloud. if err.errno == errno.EPIPE: # At this point we've caught the broken pipe, but since Python flushes # standard streams on exit, it's still possible for a broken pipe error # to happen during interpreter shutdown. The interpreter will catch this # but in Python 3 it still prints a warning to stderr saying that the # exception was ignored (see https://bugs.python.org/issue11380): # # Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' # encoding='UTF-8'> # BrokenPipeError: [Errno 32] Broken pipe # # To prevent this from happening, we redirect any remaining output to # devnull as recommended here: # https://docs.python.org/3/library/signal.html#note-on-sigpipe. devnull = os.open(os.devnull, os.O_WRONLY) os.dup2(devnull, sys.stdout.fileno()) else: raise except Exception as err: # pylint:disable=broad-except crash_handling.HandleGcloudCrash(err) if properties.VALUES.core.print_unhandled_tracebacks.GetBool(): # We want to see the traceback as normally handled by Python raise else: # This is the case for most non-Cloud SDK developers. They shouldn't see # the full stack trace, but just the nice "gcloud crashed" message. sys.exit(1) finally: for provider in credential_providers: provider.UnRegister()