Skip to content

Commit

Permalink
fail on unexpected exception + handle mac os docker
Browse files Browse the repository at this point in the history
  • Loading branch information
glicht committed Nov 26, 2020
1 parent 08ad5cf commit 7dc8fa7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
3 changes: 2 additions & 1 deletion demisto_sdk/commands/lint/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ def add_tmp_lint_files(content_repo: git.Repo, pack_path: Path, lint_files: List
added_modules.append(cur_path)
yield
except Exception as e:
logger.error(str(e))
logger.error(f'add_tmp_lint_files unexpected exception: {str(e)}')
raise
finally:
# If we want to change handling of files after finishing - do it here
pass
Expand Down
58 changes: 34 additions & 24 deletions demisto_sdk/commands/lint/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import os
import traceback
from copy import deepcopy
from typing import Any, Dict, List, Optional, Tuple

Expand Down Expand Up @@ -123,30 +124,34 @@ def run_dev_packages(self, no_flake8: bool, no_bandit: bool, no_mypy: bool, no_p
# If not python pack - skip pack
if skip:
return self._pkg_lint_status

# Locate mandatory files in pack path - for more info checkout the context manager LintFiles
with add_tmp_lint_files(content_repo=self._content_repo, # type: ignore
pack_path=self._pack_abs_dir,
lint_files=self._facts["lint_files"],
modules=modules,
pack_type=self._pkg_lint_status["pack_type"]):
# Run lint check on host - flake8, bandit, mypy
if self._pkg_lint_status["pack_type"] == TYPE_PYTHON:
self._run_lint_in_host(no_flake8=no_flake8,
no_bandit=no_bandit,
no_mypy=no_mypy,
no_vulture=no_vulture,
no_xsoar_linter=no_xsoar_linter)

# Run lint and test check on pack docker image
if self._facts["docker_engine"]:
self._run_lint_on_docker_image(no_pylint=no_pylint,
no_test=no_test,
no_pwsh_analyze=no_pwsh_analyze,
no_pwsh_test=no_pwsh_test,
keep_container=keep_container,
test_xml=test_xml)

try:
# Locate mandatory files in pack path - for more info checkout the context manager LintFiles
with add_tmp_lint_files(content_repo=self._content_repo, # type: ignore
pack_path=self._pack_abs_dir,
lint_files=self._facts["lint_files"],
modules=modules,
pack_type=self._pkg_lint_status["pack_type"]):
# Run lint check on host - flake8, bandit, mypy
if self._pkg_lint_status["pack_type"] == TYPE_PYTHON:
self._run_lint_in_host(no_flake8=no_flake8,
no_bandit=no_bandit,
no_mypy=no_mypy,
no_vulture=no_vulture,
no_xsoar_linter=no_xsoar_linter)

# Run lint and test check on pack docker image
if self._facts["docker_engine"]:
self._run_lint_on_docker_image(no_pylint=no_pylint,
no_test=no_test,
no_pwsh_analyze=no_pwsh_analyze,
no_pwsh_test=no_pwsh_test,
keep_container=keep_container,
test_xml=test_xml)
except Exception as ex:
err = f'{self._pack_abs_dir}: Unexpected fatal exception: {str(ex)}'
logger.error(f"{err}. Traceback: {traceback.format_exc()}")
self._pkg_lint_status["errors"].append(err)
self._pkg_lint_status['exit_code'] += FAIL
return self._pkg_lint_status

def _gather_facts(self, modules: dict) -> bool:
Expand Down Expand Up @@ -722,6 +727,11 @@ def _docker_run_pylint(self, test_image: str, keep_container: bool) -> Tuple[int
container_obj.remove(force=True)
except docker.errors.NotFound:
pass
except requests.exceptions.ChunkedEncodingError as err:
# see: https://github.com/docker/docker-py/issues/2696#issuecomment-721322548
if 'Connection broken: IncompleteRead' not in str(err):
raise
pass

# Run container
exit_code = SUCCESS
Expand Down

0 comments on commit 7dc8fa7

Please sign in to comment.