Skip to content

Clean up logging around exceptions #3236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def save(self, *args, **kwargs): # pylint: disable=arguments-differ
try:
self.project.sync_supported_versions()
except Exception:
log.error('failed to sync supported versions', exc_info=True)
log.exception('failed to sync supported versions')
broadcast(type='app', task=tasks.symlink_project, args=[self.project.pk])
return obj

Expand Down Expand Up @@ -224,7 +224,7 @@ def clean_build_path(self):
path, self))
rmtree(path)
except OSError:
log.error('Build path cleanup failed', exc_info=True)
log.exception('Build path cleanup failed')

def get_github_url(self, docroot, filename, source_suffix='.rst', action='view'):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ def handle(self, *args, **options):
update_search(version.pk, commit,
delete_non_commit_files=False)
except Exception:
log.error('Reindex failed for %s', version, exc_info=True)
log.exception('Reindex failed for {}'.format(version))
2 changes: 1 addition & 1 deletion readthedocs/core/management/commands/set_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ def handle(self, *args, **options):
try:
broadcast(type='app', task=tasks.update_static_metadata, args=[p.pk])
except Exception:
log.error('Build failed for %s', p, exc_info=True)
log.exception('Build failed for %s', p)
10 changes: 5 additions & 5 deletions readthedocs/core/views/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def github_build(request): # noqa: D205
ssh_search_url = ssh_url.replace('git@', '').replace('.git', '')
branches = [data['ref'].replace('refs/heads/', '')]
except (ValueError, TypeError, KeyError):
log.error('Invalid GitHub webhook payload', exc_info=True)
log.exception('Invalid GitHub webhook payload')
return HttpResponse('Invalid request', status=400)
try:
repo_projects = get_project_from_url(http_search_url)
Expand All @@ -198,7 +198,7 @@ def github_build(request): # noqa: D205
projects = repo_projects | ssh_projects
return _build_url(http_search_url, projects, branches)
except NoProjectException:
log.error('Project match not found: url=%s', http_search_url)
log.exception('Project match not found: url=%s', http_search_url)
return HttpResponseNotFound('Project not found')
else:
return HttpResponse('Method not allowed, POST is required', status=405)
Expand All @@ -222,7 +222,7 @@ def gitlab_build(request): # noqa: D205
search_url = re.sub(r'^https?://(.*?)(?:\.git|)$', '\\1', url)
branches = [data['ref'].replace('refs/heads/', '')]
except (ValueError, TypeError, KeyError):
log.error('Invalid GitLab webhook payload', exc_info=True)
log.exception('Invalid GitLab webhook payload')
return HttpResponse('Invalid request', status=400)
log.info(
'GitLab webhook search: url=%s branches=%s',
Expand Down Expand Up @@ -281,7 +281,7 @@ def bitbucket_build(request):
data['repository']['full_name']
)
except (TypeError, ValueError, KeyError):
log.error('Invalid Bitbucket webhook payload', exc_info=True)
log.exception('Invalid Bitbucket webhook payload')
return HttpResponse('Invalid request', status=400)

log.info(
Expand Down Expand Up @@ -320,7 +320,7 @@ def generic_build(request, project_id_or_slug=None):
try:
project = Project.objects.get(slug=project_id_or_slug)
except (Project.DoesNotExist, ValueError):
log.error(
log.exception(
"(Incoming Generic Build) Repo not found: %s",
project_id_or_slug)
return HttpResponseNotFound(
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/doc_builder/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def update_build(self, state=None):
except HttpClientError as e:
log.error("Unable to post a new build: %s", e.content)
except Exception:
log.error("Unknown build exception", exc_info=True)
log.exception("Unknown build exception")


class LocalEnvironment(BuildEnvironment):
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/oauth/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,5 @@ def get_token_for_project(cls, project, force_local=False):
if tokens.exists():
token = tokens[0].token
except Exception:
log.error('Failed to get token for project', exc_info=True)
log.exception('Failed to get token for project')
return token
10 changes: 5 additions & 5 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,29 +315,29 @@ def save(self, *args, **kwargs): # pylint: disable=arguments-differ
latest.identifier = self.default_branch
latest.save()
except Exception:
log.error('Failed to update latest identifier', exc_info=True)
log.exception('Failed to update latest identifier')

# Add exceptions here for safety
try:
self.sync_supported_versions()
except Exception:
log.error('failed to sync supported versions', exc_info=True)
log.exception('failed to sync supported versions')
try:
if not first_save:
broadcast(type='app', task=tasks.symlink_project, args=[self.pk])
except Exception:
log.error('failed to symlink project', exc_info=True)
log.exception('failed to symlink project')
try:
if not first_save:
broadcast(type='app', task=tasks.update_static_metadata, args=[self.pk])
except Exception:
log.error('failed to update static metadata', exc_info=True)
log.exception('failed to update static metadata')
try:
branch = self.default_branch or self.vcs_repo().fallback_branch
if not self.versions.filter(slug=LATEST).exists():
self.versions.create_latest(identifier=branch)
except Exception:
log.error('Error creating default branches', exc_info=True)
log.exception('Error creating default branches')

def get_absolute_url(self):
return reverse('projects_detail', args=[self.slug])
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def move_files(version_pk, hostname, html=False, localmedia=False, search=False,
"""
version = Version.objects.get(pk=version_pk)
log.debug(LOG_TEMPLATE.format(project=version.project.slug, version=version.slug,
msg='Moving files: {}'.format(locals())))
msg='Moving files'))

if html:
from_path = version.project.artifact_path(
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/projects/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def run(*commands):
command = ' '.join(command)
except TypeError:
run_command = command
log.info('Running command: cwd=%s command=%s', cwd, command)
log.debug('Running command: cwd=%s command=%s', cwd, command)
try:
p = subprocess.Popen(
run_command,
Expand All @@ -100,7 +100,7 @@ def run(*commands):
out = ''
err = traceback.format_exc()
ret = -1
log.error("Command failed", exc_info=True)
log.exception("Command failed")

return (ret, out, err)

Expand Down
2 changes: 1 addition & 1 deletion readthedocs/search/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def parse_mkdocs_sections(content):
# we're unsure which exceptions can be raised
# pylint: disable=bare-except
except:
log.error('Failed indexing', exc_info=True)
log.exception('Failed indexing')


def parse_sections(documentation_type, content):
Expand Down
3 changes: 1 addition & 2 deletions readthedocs/vcs_support/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def __exit__(self, exc, value, tb):
log.info("Lock (%s): Releasing", self.name)
os.remove(self.fpath)
except OSError:
log.error("Lock (%s): Failed to release, ignoring...", self.name,
exc_info=True)
log.exception("Lock (%s): Failed to release, ignoring...", self.name)


class NonBlockingLock(object):
Expand Down