Skip to content
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

Do not redirect stderr to stdout when executing commands #73

Merged
Merged
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
16 changes: 10 additions & 6 deletions scraper/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import logging.config
import os
from subprocess import PIPE, STDOUT, Popen # nosec
from subprocess import PIPE, Popen # nosec
import tempfile

logger = logging.getLogger(__name__)
Expand All @@ -22,10 +22,9 @@ def execute(command, cwd=None):
raise ValueError("path does not exist: %s" % cwd)

with Popen(
command, cwd=cwd, stdout=PIPE, stderr=STDOUT, shell=False
command, cwd=cwd, stdout=PIPE, stderr=PIPE, shell=False
) as process: # nosec
# We redirect stderr to stdout so we can safely ignore stderr in the returned tuple
out, _ = process.communicate()
out, err = process.communicate()

if process.returncode:
logging.error(
Expand All @@ -34,7 +33,7 @@ def execute(command, cwd=None):
process.returncode,
)

return out.decode("utf-8")
return out.decode("utf-8"), err.decode("utf-8")


def configure_logging(verbose=False):
Expand Down Expand Up @@ -136,7 +135,12 @@ def git_repo_to_sloc(url):
execute(cmd)

cmd = ["cloc", "--json", tmp_clone]
out = execute(cmd)
out, err = execute(cmd)

if err:
logger.warning(
"Error encountered while analyzing: url=%s stderr=%s", url, err
)

try:
cloc_json = json.loads(out)
Expand Down