|
59 | 59 |
|
60 | 60 | import click |
61 | 61 |
|
| 62 | +_BUG = click.style( |
| 63 | + 'Ahhhhhhhh! You have found a bug. 🐞\n\n', |
| 64 | + fg='red', |
| 65 | + bold=True, |
| 66 | +) |
| 67 | + |
62 | 68 | HAS_SENTRY = None |
63 | 69 | SENTRY_DSN = os.getenv('SENTRY_DSN') |
64 | 70 |
|
@@ -91,41 +97,62 @@ def __init__(self, *args, **kwargs): |
91 | 97 | def main(self, *args, **kwargs): |
92 | 98 | """Catch all exceptions.""" |
93 | 99 | try: |
94 | | - return super().main(*args, **kwargs) |
| 100 | + result = super().main(*args, **kwargs) |
| 101 | + return result |
95 | 102 | except Exception: |
96 | 103 | if HAS_SENTRY: |
97 | | - from sentry_sdk import capture_exception |
98 | | - click.echo('Sentry event ID: ' + capture_exception(), err=True) |
99 | | - raise |
| 104 | + self._handle_sentry() |
100 | 105 |
|
101 | 106 | if not (sys.stdin.isatty() and sys.stdout.isatty()): |
102 | 107 | raise |
103 | 108 |
|
104 | | - value = click.prompt( |
105 | | - click.style( |
106 | | - 'Ahhhhhhhh! You have found a bug. 🐞\n\n', |
107 | | - fg='red', |
108 | | - bold=True, |
109 | | - ) + click.style( |
110 | | - '1. Open an issue by typing "open";\n', |
111 | | - fg='green', |
112 | | - ) + click.style( |
113 | | - '2. Print human-readable information by typing ' |
114 | | - '"print";\n', |
115 | | - fg='yellow', |
116 | | - ) + click.style( |
117 | | - '3. See the full traceback without submitting details ' |
118 | | - '(default: "ignore").\n\n', |
119 | | - fg='red', |
120 | | - ) + 'Please select an action by typing its name', |
121 | | - type=click.Choice([ |
122 | | - 'open', |
123 | | - 'print', |
124 | | - 'ignore', |
125 | | - ], ), |
126 | | - default='ignore', |
| 109 | + self._handle_github() |
| 110 | + |
| 111 | + def _handle_sentry(self): |
| 112 | + """Handle exceptions using Sentry.""" |
| 113 | + from sentry_sdk import capture_exception, configure_scope |
| 114 | + from sentry_sdk.utils import capture_internal_exceptions |
| 115 | + |
| 116 | + with configure_scope() as scope: |
| 117 | + with capture_internal_exceptions(): |
| 118 | + from git import Repo |
| 119 | + from renku.cli._git import get_git_home |
| 120 | + from renku.models.datasets import Author |
| 121 | + |
| 122 | + user = Author.from_git(Repo(get_git_home())) |
| 123 | + |
| 124 | + scope.user = {'name': user.name, 'email': user.email} |
| 125 | + |
| 126 | + event_id = capture_exception() |
| 127 | + click.echo( |
| 128 | + _BUG + 'Recorded in Sentry with ID: {0}\n'.format(event_id), |
| 129 | + err=True, |
127 | 130 | ) |
128 | | - getattr(self, '_process_' + value)() |
| 131 | + raise |
| 132 | + |
| 133 | + def _handle_github(self): |
| 134 | + """Handle exception and submit it as GitHub issue.""" |
| 135 | + value = click.prompt( |
| 136 | + _BUG + click.style( |
| 137 | + '1. Open an issue by typing "open";\n', |
| 138 | + fg='green', |
| 139 | + ) + click.style( |
| 140 | + '2. Print human-readable information by typing ' |
| 141 | + '"print";\n', |
| 142 | + fg='yellow', |
| 143 | + ) + click.style( |
| 144 | + '3. See the full traceback without submitting details ' |
| 145 | + '(default: "ignore").\n\n', |
| 146 | + fg='red', |
| 147 | + ) + 'Please select an action by typing its name', |
| 148 | + type=click.Choice([ |
| 149 | + 'open', |
| 150 | + 'print', |
| 151 | + 'ignore', |
| 152 | + ], ), |
| 153 | + default='ignore', |
| 154 | + ) |
| 155 | + getattr(self, '_process_' + value)() |
129 | 156 |
|
130 | 157 | def _format_issue_title(self): |
131 | 158 | """Return formatted title.""" |
|
0 commit comments