MCPcopy
hub / github.com/GitGuardian/ggshield / handle_exception

Function handle_exception

ggshield/core/errors.py:174–208  ·  view source on GitHub ↗

Take an exception, print information about it and return the exit code to use

(exc: Exception)

Source from the content-addressed store, hash-verified

172
173
174def handle_exception(exc: Exception) -> int:
175 """
176 Take an exception, print information about it and return the exit code to use
177 """
178 # TODO: fix this. It's required to avoid a circular import error
179 from ggshield.core import ui
180
181 if isinstance(exc, click.exceptions.Abort):
182 return ExitCode.SUCCESS
183
184 # Get exit code
185 if isinstance(exc, _ExitError):
186 exit_code = exc.exit_code
187 elif isinstance(exc, (InvalidGitRefError, click.UsageError)):
188 exit_code = ExitCode.USAGE_ERROR
189 else:
190 exit_code = ExitCode.UNEXPECTED_ERROR
191
192 click.echo()
193 ui.display_error(str(exc))
194 if isinstance(exc, UnicodeEncodeError) and platform.system() == "Windows":
195 ui.display_info(
196 "\n"
197 "ggshield failed to print a message because of an Unicode encoding issue."
198 " To workaround that, try setting the PYTHONUTF8 environment variable to 1."
199 )
200
201 if not isinstance(exc, click.ClickException):
202 click.echo()
203 if ui.is_verbose():
204 traceback.print_exc()
205 else:
206 ui.display_info("Re-run the command with --verbose to get a stack trace.")
207
208 return exit_code
209
210
211def handle_api_error(detail: Detail) -> None:

Callers 3

wrapperFunction · 0.90
_execute_prereceiveFunction · 0.90
scan_repo_pathFunction · 0.90

Calls 2

display_errorMethod · 0.80
display_infoMethod · 0.80

Tested by

no test coverage detected