From 547cfb00453c767269a4e2a1986e0cecd6df263f Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Wed, 8 Nov 2017 12:47:43 -0700 Subject: [PATCH 1/3] Clean up logging around exceptions --- readthedocs/builds/models.py | 4 ++-- .../core/management/commands/reindex_elasticsearch.py | 2 +- readthedocs/core/management/commands/set_metadata.py | 2 +- readthedocs/core/views/hooks.py | 10 +++++----- readthedocs/doc_builder/environments.py | 2 +- readthedocs/oauth/services/github.py | 2 +- readthedocs/projects/models.py | 10 +++++----- readthedocs/projects/utils.py | 4 ++-- readthedocs/search/utils.py | 2 +- readthedocs/vcs_support/utils.py | 3 +-- 10 files changed, 20 insertions(+), 21 deletions(-) diff --git a/readthedocs/builds/models.py b/readthedocs/builds/models.py index f3927178987..10d8a9e5aa6 100644 --- a/readthedocs/builds/models.py +++ b/readthedocs/builds/models.py @@ -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 @@ -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'): """ diff --git a/readthedocs/core/management/commands/reindex_elasticsearch.py b/readthedocs/core/management/commands/reindex_elasticsearch.py index 731dc861af6..e1094068b3e 100644 --- a/readthedocs/core/management/commands/reindex_elasticsearch.py +++ b/readthedocs/core/management/commands/reindex_elasticsearch.py @@ -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 %s'.format(version)) diff --git a/readthedocs/core/management/commands/set_metadata.py b/readthedocs/core/management/commands/set_metadata.py index 2f8014cf828..dbefcddbdd0 100644 --- a/readthedocs/core/management/commands/set_metadata.py +++ b/readthedocs/core/management/commands/set_metadata.py @@ -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) diff --git a/readthedocs/core/views/hooks.py b/readthedocs/core/views/hooks.py index 3525fb88177..2a438f27da8 100644 --- a/readthedocs/core/views/hooks.py +++ b/readthedocs/core/views/hooks.py @@ -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) @@ -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) @@ -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', @@ -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( @@ -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( diff --git a/readthedocs/doc_builder/environments.py b/readthedocs/doc_builder/environments.py index 3fa97b0d036..7fb8f7e592e 100644 --- a/readthedocs/doc_builder/environments.py +++ b/readthedocs/doc_builder/environments.py @@ -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): diff --git a/readthedocs/oauth/services/github.py b/readthedocs/oauth/services/github.py index a0c630b1a3a..9472f20825f 100644 --- a/readthedocs/oauth/services/github.py +++ b/readthedocs/oauth/services/github.py @@ -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 diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py index f7c3adb32d5..9dc5a682367 100644 --- a/readthedocs/projects/models.py +++ b/readthedocs/projects/models.py @@ -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]) diff --git a/readthedocs/projects/utils.py b/readthedocs/projects/utils.py index 86e2040d03c..2683ec59cfb 100644 --- a/readthedocs/projects/utils.py +++ b/readthedocs/projects/utils.py @@ -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, @@ -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) diff --git a/readthedocs/search/utils.py b/readthedocs/search/utils.py index 07eb38cd1f8..385e1110804 100644 --- a/readthedocs/search/utils.py +++ b/readthedocs/search/utils.py @@ -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): diff --git a/readthedocs/vcs_support/utils.py b/readthedocs/vcs_support/utils.py index f4e2018a010..5dd59c80f1b 100644 --- a/readthedocs/vcs_support/utils.py +++ b/readthedocs/vcs_support/utils.py @@ -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): From 94df0ccef9dafcbef8e05159b5943a28a08360b3 Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Wed, 8 Nov 2017 16:19:42 -0700 Subject: [PATCH 2/3] Another one --- readthedocs/projects/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readthedocs/projects/tasks.py b/readthedocs/projects/tasks.py index a52fa80c3af..d197520e203 100644 --- a/readthedocs/projects/tasks.py +++ b/readthedocs/projects/tasks.py @@ -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( From fc8728798a22a225d65728aa8b0e02aee9989741 Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Wed, 8 Nov 2017 17:00:45 -0700 Subject: [PATCH 3/3] Fix lint --- readthedocs/core/management/commands/reindex_elasticsearch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readthedocs/core/management/commands/reindex_elasticsearch.py b/readthedocs/core/management/commands/reindex_elasticsearch.py index e1094068b3e..a2bce6df840 100644 --- a/readthedocs/core/management/commands/reindex_elasticsearch.py +++ b/readthedocs/core/management/commands/reindex_elasticsearch.py @@ -53,4 +53,4 @@ def handle(self, *args, **options): update_search(version.pk, commit, delete_non_commit_files=False) except Exception: - log.exception('Reindex failed for %s'.format(version)) + log.exception('Reindex failed for {}'.format(version))