Skip to content

Commit f093076

Browse files
authored
Merge pull request #3236 from rtfd/fix-more-logging
Clean up logging around exceptions
2 parents 2ac95a9 + fc87287 commit f093076

File tree

11 files changed

+21
-22
lines changed

11 files changed

+21
-22
lines changed

readthedocs/builds/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def save(self, *args, **kwargs): # pylint: disable=arguments-differ
155155
try:
156156
self.project.sync_supported_versions()
157157
except Exception:
158-
log.error('failed to sync supported versions', exc_info=True)
158+
log.exception('failed to sync supported versions')
159159
broadcast(type='app', task=tasks.symlink_project, args=[self.project.pk])
160160
return obj
161161

@@ -224,7 +224,7 @@ def clean_build_path(self):
224224
path, self))
225225
rmtree(path)
226226
except OSError:
227-
log.error('Build path cleanup failed', exc_info=True)
227+
log.exception('Build path cleanup failed')
228228

229229
def get_github_url(self, docroot, filename, source_suffix='.rst', action='view'):
230230
"""

readthedocs/core/management/commands/reindex_elasticsearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ def handle(self, *args, **options):
5353
update_search(version.pk, commit,
5454
delete_non_commit_files=False)
5555
except Exception:
56-
log.error('Reindex failed for %s', version, exc_info=True)
56+
log.exception('Reindex failed for {}'.format(version))

readthedocs/core/management/commands/set_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ def handle(self, *args, **options):
2323
try:
2424
broadcast(type='app', task=tasks.update_static_metadata, args=[p.pk])
2525
except Exception:
26-
log.error('Build failed for %s', p, exc_info=True)
26+
log.exception('Build failed for %s', p)

readthedocs/core/views/hooks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def github_build(request): # noqa: D205
178178
ssh_search_url = ssh_url.replace('git@', '').replace('.git', '')
179179
branches = [data['ref'].replace('refs/heads/', '')]
180180
except (ValueError, TypeError, KeyError):
181-
log.error('Invalid GitHub webhook payload', exc_info=True)
181+
log.exception('Invalid GitHub webhook payload')
182182
return HttpResponse('Invalid request', status=400)
183183
try:
184184
repo_projects = get_project_from_url(http_search_url)
@@ -198,7 +198,7 @@ def github_build(request): # noqa: D205
198198
projects = repo_projects | ssh_projects
199199
return _build_url(http_search_url, projects, branches)
200200
except NoProjectException:
201-
log.error('Project match not found: url=%s', http_search_url)
201+
log.exception('Project match not found: url=%s', http_search_url)
202202
return HttpResponseNotFound('Project not found')
203203
else:
204204
return HttpResponse('Method not allowed, POST is required', status=405)
@@ -222,7 +222,7 @@ def gitlab_build(request): # noqa: D205
222222
search_url = re.sub(r'^https?://(.*?)(?:\.git|)$', '\\1', url)
223223
branches = [data['ref'].replace('refs/heads/', '')]
224224
except (ValueError, TypeError, KeyError):
225-
log.error('Invalid GitLab webhook payload', exc_info=True)
225+
log.exception('Invalid GitLab webhook payload')
226226
return HttpResponse('Invalid request', status=400)
227227
log.info(
228228
'GitLab webhook search: url=%s branches=%s',
@@ -281,7 +281,7 @@ def bitbucket_build(request):
281281
data['repository']['full_name']
282282
)
283283
except (TypeError, ValueError, KeyError):
284-
log.error('Invalid Bitbucket webhook payload', exc_info=True)
284+
log.exception('Invalid Bitbucket webhook payload')
285285
return HttpResponse('Invalid request', status=400)
286286

287287
log.info(
@@ -320,7 +320,7 @@ def generic_build(request, project_id_or_slug=None):
320320
try:
321321
project = Project.objects.get(slug=project_id_or_slug)
322322
except (Project.DoesNotExist, ValueError):
323-
log.error(
323+
log.exception(
324324
"(Incoming Generic Build) Repo not found: %s",
325325
project_id_or_slug)
326326
return HttpResponseNotFound(

readthedocs/doc_builder/environments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def update_build(self, state=None):
433433
except HttpClientError as e:
434434
log.error("Unable to post a new build: %s", e.content)
435435
except Exception:
436-
log.error("Unknown build exception", exc_info=True)
436+
log.exception("Unknown build exception")
437437

438438

439439
class LocalEnvironment(BuildEnvironment):

readthedocs/oauth/services/github.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,5 @@ def get_token_for_project(cls, project, force_local=False):
289289
if tokens.exists():
290290
token = tokens[0].token
291291
except Exception:
292-
log.error('Failed to get token for project', exc_info=True)
292+
log.exception('Failed to get token for project')
293293
return token

readthedocs/projects/models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,29 +315,29 @@ def save(self, *args, **kwargs): # pylint: disable=arguments-differ
315315
latest.identifier = self.default_branch
316316
latest.save()
317317
except Exception:
318-
log.error('Failed to update latest identifier', exc_info=True)
318+
log.exception('Failed to update latest identifier')
319319

320320
# Add exceptions here for safety
321321
try:
322322
self.sync_supported_versions()
323323
except Exception:
324-
log.error('failed to sync supported versions', exc_info=True)
324+
log.exception('failed to sync supported versions')
325325
try:
326326
if not first_save:
327327
broadcast(type='app', task=tasks.symlink_project, args=[self.pk])
328328
except Exception:
329-
log.error('failed to symlink project', exc_info=True)
329+
log.exception('failed to symlink project')
330330
try:
331331
if not first_save:
332332
broadcast(type='app', task=tasks.update_static_metadata, args=[self.pk])
333333
except Exception:
334-
log.error('failed to update static metadata', exc_info=True)
334+
log.exception('failed to update static metadata')
335335
try:
336336
branch = self.default_branch or self.vcs_repo().fallback_branch
337337
if not self.versions.filter(slug=LATEST).exists():
338338
self.versions.create_latest(identifier=branch)
339339
except Exception:
340-
log.error('Error creating default branches', exc_info=True)
340+
log.exception('Error creating default branches')
341341

342342
def get_absolute_url(self):
343343
return reverse('projects_detail', args=[self.slug])

readthedocs/projects/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ def move_files(version_pk, hostname, html=False, localmedia=False, search=False,
624624
"""
625625
version = Version.objects.get(pk=version_pk)
626626
log.debug(LOG_TEMPLATE.format(project=version.project.slug, version=version.slug,
627-
msg='Moving files: {}'.format(locals())))
627+
msg='Moving files'))
628628

629629
if html:
630630
from_path = version.project.artifact_path(

readthedocs/projects/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def run(*commands):
8484
command = ' '.join(command)
8585
except TypeError:
8686
run_command = command
87-
log.info('Running command: cwd=%s command=%s', cwd, command)
87+
log.debug('Running command: cwd=%s command=%s', cwd, command)
8888
try:
8989
p = subprocess.Popen(
9090
run_command,
@@ -100,7 +100,7 @@ def run(*commands):
100100
out = ''
101101
err = traceback.format_exc()
102102
ret = -1
103-
log.error("Command failed", exc_info=True)
103+
log.exception("Command failed")
104104

105105
return (ret, out, err)
106106

readthedocs/search/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def parse_mkdocs_sections(content):
266266
# we're unsure which exceptions can be raised
267267
# pylint: disable=bare-except
268268
except:
269-
log.error('Failed indexing', exc_info=True)
269+
log.exception('Failed indexing')
270270

271271

272272
def parse_sections(documentation_type, content):

readthedocs/vcs_support/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ def __exit__(self, exc, value, tb):
5757
log.info("Lock (%s): Releasing", self.name)
5858
os.remove(self.fpath)
5959
except OSError:
60-
log.error("Lock (%s): Failed to release, ignoring...", self.name,
61-
exc_info=True)
60+
log.exception("Lock (%s): Failed to release, ignoring...", self.name)
6261

6362

6463
class NonBlockingLock(object):

0 commit comments

Comments
 (0)