gurudesh/pytracebugs huggingface dataset:
# Buggy code
def __call__(self, data):
    d = dict(data)
    for idx, key in enumerate(self.keys):
        d[key] = self.rotator(
            d[key],
            mode=self.mode[idx],
            padding_mode=self.padding_mode[idx],
            align_corners=self.align_corners[idx],
        )
    return d


# Traceback (AssertionError)
======================================================================
FAIL: test_training (__main__.IntegrationSegmentation3D)
----------------------------------------------------------------------
Traceback (most recent call last):
File "tests/test_integration_segmentation_3d.py", line 257, in test_training
rtol=1e-3,
File "/opt/conda/lib/python3.6/site-packages/numpy/testing/_private/utils.py", line 1533, in assert_allclose
verbose=verbose, header=header, equal_nan=equal_nan)
File "/opt/conda/lib/python3.6/site-packages/numpy/testing/_private/utils.py", line 846, in assert_array_compare
raise AssertionError(msg)
AssertionError:
Not equal to tolerance rtol=0.001, atol=0

Mismatched elements: 6 / 6 (100%)
Max absolute difference: 0.01720129
Max relative difference: 0.04047175
x: array([0.543151, 0.471052, 0.453605, 0.438546, 0.437794, 0.407818])
y: array([0.544673, 0.475109, 0.444963, 0.427036, 0.433381, 0.42502 ])

----------------------------------------------------------------------
Ran 1 test in 92.377s

FAILED (failures=1)

# Fixed code
def __call__(self, data):
    d = dict(data)
    for idx, key in enumerate(self.keys):
        d[key] = self.rotator(
            d[key],
            mode=self.mode[idx],
            padding_mode=self.padding_mode[idx],
            align_corners=self.align_corners[idx],
            dtype=self.dtype[idx],
        )
    return d
# Buggy code
def __call__(self, data):
    self.randomize()
    d = dict(data)
    if not self._do_transform:
        return d
    rotator = Rotate(
        angle=self.x if d[self.keys[0]].ndim == 3 else (self.x, self.y, self.z),
        keep_size=self.keep_size,
    )
    for idx, key in enumerate(self.keys):
        d[key] = rotator(
            d[key],
            mode=self.mode[idx],
            padding_mode=self.padding_mode[idx],
            align_corners=self.align_corners[idx],
        )
    return d


# Traceback (AssertionError)
======================================================================
FAIL: test_training (__main__.IntegrationSegmentation3D)
----------------------------------------------------------------------
Traceback (most recent call last):
File "tests/test_integration_segmentation_3d.py", line 257, in test_training
rtol=1e-3,
File "/opt/conda/lib/python3.6/site-packages/numpy/testing/_private/utils.py", line 1533, in assert_allclose
verbose=verbose, header=header, equal_nan=equal_nan)
File "/opt/conda/lib/python3.6/site-packages/numpy/testing/_private/utils.py", line 846, in assert_array_compare
raise AssertionError(msg)
AssertionError:
Not equal to tolerance rtol=0.001, atol=0

Mismatched elements: 6 / 6 (100%)
Max absolute difference: 0.01720129
Max relative difference: 0.04047175
x: array([0.543151, 0.471052, 0.453605, 0.438546, 0.437794, 0.407818])
y: array([0.544673, 0.475109, 0.444963, 0.427036, 0.433381, 0.42502 ])

----------------------------------------------------------------------
Ran 1 test in 92.377s

FAILED (failures=1)

# Fixed code
def __call__(self, data):
    self.randomize()
    d = dict(data)
    if not self._do_transform:
        return d
    rotator = Rotate(
        angle=self.x if d[self.keys[0]].ndim == 3 else (self.x, self.y, self.z),
        keep_size=self.keep_size,
    )
    for idx, key in enumerate(self.keys):
        d[key] = rotator(
            d[key],
            mode=self.mode[idx],
            padding_mode=self.padding_mode[idx],
            align_corners=self.align_corners[idx],
            dtype=self.dtype[idx],
        )
    return d
# Buggy code
def print_versions(*, file=None):
    """Print print versions of imported packages"""
    if file is None:  # Inform people about the behavior change
        warning("If you miss a compact list, please try `print_header`!")
    stdout = sys.stdout
    try:
        buf = sys.stdout = io.StringIO()
        sinfo(dependencies=True)
    finally:
        sys.stdout = stdout
    output = buf.getvalue()
    print(output, file=file)


# Traceback (AttributeError)
WARNING: If you miss a compact list, please try `print_header`!
Traceback (most recent call last):
File "/home/sturm/anaconda3/envs/scanpy_test/lib/python3.7/site-packages/sinfo/main.py", line 195, in sinfo
mod_version = _find_version(mod.__version__)
AttributeError: module 'importlib_metadata' has no attribute '__version__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sturm/anaconda3/envs/scanpy_test/lib/python3.7/site-packages/scanpy/logging.py", line 161, in print_versions
sinfo(dependencies=True)
File "/home/sturm/anaconda3/envs/scanpy_test/lib/python3.7/site-packages/sinfo/main.py", line 198, in sinfo
mod_version = _find_version(mod.version)
File "/home/sturm/anaconda3/envs/scanpy_test/lib/python3.7/site-packages/sinfo/main.py", line 42, in _find_version
return mod_version_attr()
TypeError: version() missing 1 required positional argument: 'distribution_name'

# Fixed code
def print_versions(*, file=None):
    """Print print versions of imported packages"""
    if file is None:  # Inform people about the behavior change
        warning("If you miss a compact list, please try `print_header`!")
    stdout = sys.stdout
    try:
        buf = sys.stdout = io.StringIO()
        sinfo(
            dependencies=True,
            excludes=[
                "builtins",
                "stdlib_list",
                "importlib_metadata",
                # Special module present if test coverage being calculated
                # https://gitlab.com/joelostblom/sinfo/-/issues/10
                "$coverage",
            ],
        )
    finally:
        sys.stdout = stdout
    output = buf.getvalue()
    print(output, file=file)
# Buggy code
def recipe_seurat(
    adata: AnnData,
    log: bool = True,
    plot: bool = False,
    copy: bool = False,
) -> Optional[AnnData]:
    """\
    Normalization and filtering as of Seurat [Satija15]_.

    This uses a particular preprocessing.

    Expects non-logarithmized data.
    If using logarithmized data, pass `log=False`.
    """
    if copy:
        adata = adata.copy()
    pp.filter_cells(adata, min_genes=200)
    pp.filter_genes(adata, min_cells=3)
    normalize_total(adata, target_sum=1e4)
    filter_result = filter_genes_dispersion(
        adata.X, min_mean=0.0125, max_mean=3, min_disp=0.5, log=not log
    )
    if plot:
        from ..plotting import (
            _preprocessing as ppp,
        )  # should not import at the top of the file

        ppp.filter_genes_dispersion(filter_result, log=not log)
    adata._inplace_subset_var(filter_result.gene_subset)  # filter genes
    if log:
        pp.log1p(adata)
    pp.scale(adata, max_value=10)
    return adata if copy else None


# Traceback (AttributeError)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-bfa4168a87e6> in <module>
1 adata.raw = adata
----> 2 sc.pp.recipe_weinreb17(adata, log=False)
3 sc.tl.pca(adata)

/opt/anaconda3/lib/python3.7/site-packages/scanpy/preprocessing/_recipes.py in recipe_weinreb17(adata, log, mean_threshold, cv_threshold, n_pcs, svd_solver, random_state, copy)
48     )
49     adata._inplace_subset_var(gene_subset)  # this modifies the object itself
---> 50     X_pca = pp.pca(
51         pp.zscore_deprecated(adata.X),
52         n_comps=n_pcs,

AttributeError: module 'scanpy.preprocessing._simple' has no attribute 'pca'

# Fixed code
def recipe_seurat(
    adata: AnnData,
    log: bool = True,
    plot: bool = False,
    copy: bool = False,
) -> Optional[AnnData]:
    """\
    Normalization and filtering as of Seurat [Satija15]_.

    This uses a particular preprocessing.

    Expects non-logarithmized data.
    If using logarithmized data, pass `log=False`.
    """
    if copy:
        adata = adata.copy()
    pp.filter_cells(adata, min_genes=200)
    pp.filter_genes(adata, min_cells=3)
    normalize_total(adata, target_sum=1e4)
    filter_result = filter_genes_dispersion(
        adata.X, min_mean=0.0125, max_mean=3, min_disp=0.5, log=not log
    )
    if plot:
        from ..plotting import (
            _preprocessing as ppp,
        )  # should not import at the top of the file

        ppp.filter_genes_dispersion(filter_result, log=not log)
    adata._inplace_subset_var(filter_result.gene_subset)  # filter genes
    if log:
        pp.log1p(adata)
    pp.scale(adata, max_value=10)
    return adata if copy else None
# Buggy code
def _download_visium_dataset(sample_id: str, base_dir: Optional[Path] = None):
    """
    Params
    ------
    sample_id
        String name of example visium dataset.
    base_dir
        Where to download the dataset to.
    """
    import tarfile

    if base_dir is None:
        base_dir = settings.datasetdir

    url_prefix = f"http://cf.10xgenomics.com/samples/spatial-exp/1.0.0/{sample_id}/"

    sample_dir = base_dir / sample_id
    sample_dir.mkdir(exist_ok=True)

    # Download spatial data
    tar_filename = f"{sample_id}_spatial.tar.gz"
    tar_pth = sample_dir / tar_filename
    _utils.check_presence_download(
        filename=tar_pth, backup_url=url_prefix + tar_filename
    )
    with tarfile.open(tar_pth) as f:
        for el in f:
            if not (sample_dir / el.name).exists():
                f.extract(el, sample_dir)

    # Download counts
    _utils.check_presence_download(
        filename=sample_dir / "filtered_feature_bc_matrix.h5",
        backup_url=url_prefix + f"{sample_id}_filtered_feature_bc_matrix.h5",
    )


# Traceback (FileNotFoundError)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/lisa/data/V1_Breast_Cancer_Block_A_Section_1'

# Fixed code
def _download_visium_dataset(sample_id: str, base_dir: Optional[Path] = None):
    """
    Params
    ------
    sample_id
        String name of example visium dataset.
    base_dir
        Where to download the dataset to.
    """
    import tarfile

    if base_dir is None:
        base_dir = settings.datasetdir

    url_prefix = f"http://cf.10xgenomics.com/samples/spatial-exp/1.0.0/{sample_id}/"

    sample_dir = base_dir / sample_id
    sample_dir.mkdir(exist_ok=True, parents=True)

    # Download spatial data
    tar_filename = f"{sample_id}_spatial.tar.gz"
    tar_pth = sample_dir / tar_filename
    _utils.check_presence_download(
        filename=tar_pth, backup_url=url_prefix + tar_filename
    )
    with tarfile.open(tar_pth) as f:
        for el in f:
            if not (sample_dir / el.name).exists():
                f.extract(el, sample_dir)

    # Download counts
    _utils.check_presence_download(
        filename=sample_dir / "filtered_feature_bc_matrix.h5",
        backup_url=url_prefix + f"{sample_id}_filtered_feature_bc_matrix.h5",
    )
# Buggy code
def _download(url: str, path: Path):
    from tqdm.auto import tqdm
    from urllib.request import urlretrieve

    path.parent.mkdir(parents=True, exist_ok=True)
    with tqdm(unit="B", unit_scale=True, miniters=1, desc=path.name) as t:

        def update_to(b=1, bsize=1, tsize=None):
            if tsize is not None:
                t.total = tsize
            t.update(b * bsize - t.n)

        try:
            urlretrieve(url, str(path), reporthook=update_to)
        except Exception:
            # Make sure file doesn’t exist half-downloaded
            path.unlink(missing_ok=True)
            raise


# Traceback (TypeError)
/scanpy/scanpy/datasets/_ebi_expression_atlas.py in download_experiment(accession)
41
42     _download(
---> 43         download_url + "experiment-design", experiment_dir / "experimental_design.tsv",
44     )
45     _download(

/scanpy/scanpy/readwrite.py in _download(url, path)
877         except Exception:
878             # Make sure file doesn’t exist half-downloaded
--> 879             path.unlink(missing_ok=True)
880             raise
881

TypeError: unlink() got an unexpected keyword argument 'missing_ok'

...

# Fixed code
def _download(url: str, path: Path):
    from tqdm.auto import tqdm
    from urllib.request import urlretrieve

    path.parent.mkdir(parents=True, exist_ok=True)
    with tqdm(unit="B", unit_scale=True, miniters=1, desc=path.name) as t:

        def update_to(b=1, bsize=1, tsize=None):
            if tsize is not None:
                t.total = tsize
            t.update(b * bsize - t.n)

        try:
            urlretrieve(url, str(path), reporthook=update_to)
        except Exception:
            # Make sure file doesn’t exist half-downloaded
            if path.is_file():
                path.unlink()
            raise
# Buggy code
def _enrich_anndata(
    adata: AnnData,
    group: str,
    *,
    org: Optional[str] = "hsapiens",
    key: str = "rank_genes_groups",
    pval_cutoff: float = 0.05,
    log2fc_min: Optional[float] = None,
    log2fc_max: Optional[float] = None,
    gene_symbols: Optional[str] = None,
    gprofiler_kwargs: Mapping[str, Any] = MappingProxyType({}),
) -> pd.DataFrame:
    de = rank_genes_groups_df(
        adata,
        group=group,
        key=key,
        pval_cutoff=pval_cutoff,
        log2fc_min=log2fc_min,
        log2fc_max=log2fc_max,
        gene_symbols=gene_symbols,
    )
    if gene_symbols is not None:
        gene_list = list(de[gene_symbols])
    else:
        gene_list = list(de["names"])
    return enrich(gene_list, org=org, gprofiler_kwargs=gprofiler_kwargs)


# Traceback (AssertionError)
AssertionError: query failed with error 500

# Fixed code
def _enrich_anndata(
    adata: AnnData,
    group: str,
    *,
    org: Optional[str] = "hsapiens",
    key: str = "rank_genes_groups",
    pval_cutoff: float = 0.05,
    log2fc_min: Optional[float] = None,
    log2fc_max: Optional[float] = None,
    gene_symbols: Optional[str] = None,
    gprofiler_kwargs: Mapping[str, Any] = MappingProxyType({}),
) -> pd.DataFrame:
    de = rank_genes_groups_df(
        adata,
        group=group,
        key=key,
        pval_cutoff=pval_cutoff,
        log2fc_min=log2fc_min,
        log2fc_max=log2fc_max,
        gene_symbols=gene_symbols,
    )
    if gene_symbols is not None:
        gene_list = list(de[gene_symbols].dropna())
    else:
        gene_list = list(de["names"].dropna())
    return enrich(gene_list, org=org, gprofiler_kwargs=gprofiler_kwargs)
# Buggy code
def enforce_max_size(token_embedding, size):
    assert token_embedding.idx_to_vec is not None
    if size and len(token_embedding.idx_to_token) > size:
        assert size > 0
        size = size + 1 if token_embedding.unknown_token is not None else size
        token_embedding._idx_to_token = token_embedding._idx_to_token[:size]
        token_embedding._idx_to_vec = token_embedding._idx_to_vec[:size]
        token_embedding._token_to_idx = {
            token: idx for idx, token in enumerate(token_embedding._idx_to_token)
        }


# Traceback (KeyError)
Traceback (most recent call last):
File "evaluate_pretrained.py", line 216, in <module>
vocab.set_embedding(token_embedding_)
File "/Users/siyuanl/private/gluon-nlp/src/gluonnlp/vocab/vocab.py", line 412, in set_embedding
new_idx_to_vec[1:, col_start:col_end] = embs[self._idx_to_token[1:]]
File "/Users/siyuanl/private/gluon-nlp/src/gluonnlp/embedding/token_embedding.py", line 637, in __getitem__
indices = [self._token_to_idx[token] for token in tokens]
File "/Users/siyuanl/private/gluon-nlp/src/gluonnlp/embedding/token_embedding.py", line 637, in <listcomp>
indices = [self._token_to_idx[token] for token in tokens]
KeyError: '<pad>'

# Fixed code
def enforce_max_size(token_embedding, size):
    assert token_embedding.idx_to_vec is not None
    if size and len(token_embedding.idx_to_token) > size:
        assert size > 0
        size = size + 1 if token_embedding.unknown_token is not None else size
        token_embedding = nlp.embedding.TokenEmbedding(
            unknown_token=token_embedding.unknown_token,
            idx_to_token=token_embedding._idx_to_token[:size],
            idx_to_vec=token_embedding._idx_to_vec[:size],
            unknown_lookup=token_embedding.unknown_lookup,
        )
    return token_embedding
# Buggy code
def load_cached_dataset(prefix):
    cached_file_path = os.path.join(_C.CACHE_PATH, prefix + ".npz")
    if os.path.exists(cached_file_path):
        print("Load cached data from {}".format(cached_file_path))
        dat = np.load(cached_file_path)
        return ArrayDataset(np.array(dat["src_data"]), np.array(dat["tgt_data"]))
    else:
        return None


# Traceback (UnicodeDecodeError)
2018-09-26 05:38:28,761 - root - Namespace(average_checkpoint=False, average_start=5, batch_size=2700, beam_size=4, bleu='13a', bucket_ratio=0.0, bucket_scheme='exp', dataset='WMT2$
14BPE', dropout=0.1, epochs=30, epsilon=0.1, full=False, gpus='0,1,2,3,4,5,6,7', hidden_size=2048, log_interval=10, lp_alpha=0.6, lp_k=5, lr=2.0, magnitude=3.0, num_accumulated=16,
num_averages=5, num_buckets=20, num_heads=8, num_layers=6, num_units=512, optimizer='adam', save_dir='transformer_en_de_u512', scaled=True, src_lang='en', src_max_len=-1, test_batc$
_size=256, tgt_lang='de', tgt_max_len=-1, warmup_steps=4000.0)
All Logs will be saved to transformer_en_de_u512/train_transformer.log
Load cached data from /home/ubuntu/transformer/scripts/nmt/cached/WMT2014BPE_en_de_-1_-1_train.npz
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/numpy/lib/format.py", line 650, in read_array
array = pickle.load(fp, **pickle_kwargs)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xfa in position 8: ordinal not in range(128)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "train_transformer.py", line 304, in <module>
= load_translation_data(dataset=args.dataset, src_lang=args.src_lang, tgt_lang=args.tgt_lang)
File "train_transformer.py", line 260, in load_translation_data
data_train_processed = load_cached_dataset(common_prefix + '_train')
File "train_transformer.py", line 167, in load_cached_dataset
return ArrayDataset(np.array(dat['src_data']), np.array(dat['tgt_data']))
File "/usr/local/lib/python3.5/dist-packages/numpy/lib/npyio.py", line 235, in __getitem__
pickle_kwargs=self.pickle_kwargs)
File "/usr/local/lib/python3.5/dist-packages/numpy/lib/format.py", line 656, in read_array
"to numpy.load" % (err,))
UnicodeError: Unpickling a python object failed: UnicodeDecodeError('ascii', b'\x07 \x00\x00ls\x00\x00\xfab\x00\x00k]\x00\x00`p\x00\x00fi\x00\x00\x03\x00\x00\x00', 8, 9, 'ordinal n$
t in range(128)')
You may need to pass the encoding= option to numpy.load

# Fixed code
def load_cached_dataset(prefix):
    cached_file_path = os.path.join(_C.CACHE_PATH, prefix + ".npz")
    if os.path.exists(cached_file_path):
        print("Load cached data from {}".format(cached_file_path))
        dat = np.load(cached_file_path, encoding="latin1")
        return ArrayDataset(np.array(dat["src_data"]), np.array(dat["tgt_data"]))
    else:
        return None
# Buggy code
def remove_user(self, group_item, user_id):
    self._remove_user(group_item, user_id)
    try:
        user_set = group_item.users
        for user in user_set:
            if user.id == user_id:
                user_set.remove(user)
                break
    except UnpopulatedPropertyError:
        # If we aren't populated, do nothing to the user list
        pass
    logger.info(
        "Removed user (id: {0}) from group (ID: {1})".format(user_id, group_item.id)
    )


# Traceback (AttributeError)
Traceback (most recent call last):
File "create_group.py", line 50, in <module>
main()
File "create_group.py", line 45, in main
server.groups.add_user(group, new_user._id)
File "/Library/Python/2.7/site-packages/tableauserverclient/server/endpoint/groups_endpoint.py", line 70, in add_user
user_set.add(new_user)
AttributeError: 'list' object has no attribute 'add'

# Fixed code
def remove_user(self, group_item, user_id):
    self._remove_user(group_item, user_id)
    try:
        users = group_item.users
        for user in users:
            if user.id == user_id:
                users.remove(user)
                break
    except UnpopulatedPropertyError:
        # If we aren't populated, do nothing to the user list
        pass
    logger.info(
        "Removed user (id: {0}) from group (ID: {1})".format(user_id, group_item.id)
    )
# Buggy code
def add_user(self, group_item, user_id):
    new_user = self._add_user(group_item, user_id)
    try:
        user_set = group_item.users
        user_set.add(new_user)
        group_item._set_users(user_set)
    except UnpopulatedPropertyError:
        # If we aren't populated, do nothing to the user list
        pass
    logger.info(
        "Added user (id: {0}) to group (ID: {1})".format(user_id, group_item.id)
    )


# Traceback (AttributeError)
Traceback (most recent call last):
File "create_group.py", line 50, in <module>
main()
File "create_group.py", line 45, in main
server.groups.add_user(group, new_user._id)
File "/Library/Python/2.7/site-packages/tableauserverclient/server/endpoint/groups_endpoint.py", line 70, in add_user
user_set.add(new_user)
AttributeError: 'list' object has no attribute 'add'

# Fixed code
def add_user(self, group_item, user_id):
    new_user = self._add_user(group_item, user_id)
    try:
        users = group_item.users
        users.append(new_user)
        group_item._set_users(users)
    except UnpopulatedPropertyError:
        # If we aren't populated, do nothing to the user list
        pass
    logger.info(
        "Added user (id: {0}) to group (ID: {1})".format(user_id, group_item.id)
    )
# Buggy code
def _fetchable_partitions(self):
    fetchable = self._subscriptions.fetchable_partitions()
    if self._next_partition_records:
        fetchable.discard(self._next_partition_records.topic_partition)
    for fetch in self._completed_fetches:
        fetchable.discard(fetch.topic_partition)
    return fetchable


# Traceback (RuntimeError)
Traceback (most recent call last):
[...]
File "[...]/kafka/consumer/group.py", line 603, in poll
records = self._poll_once(remaining, max_records)
File "[...]/kafka/consumer/group.py", line 643, in _poll_once
self._fetcher.send_fetches()
File "[...]/kafka/consumer/fetcher.py", line 131, in send_fetches
for node_id, request in six.iteritems(self._create_fetch_requests()):
File "[...]/kafka/consumer/fetcher.py", line 652, in _create_fetch_requests
for partition in self._fetchable_partitions():
File "[...]/kafka/consumer/fetcher.py", line 636, in _fetchable_partitions
for fetch in self._completed_fetches:
RuntimeError: deque mutated during iteration

# Fixed code
def _fetchable_partitions(self):
    fetchable = self._subscriptions.fetchable_partitions()
    # do not fetch a partition if we have a pending fetch response to process
    current = self._next_partition_records
    pending = copy.copy(self._completed_fetches)
    if current:
        fetchable.discard(current.topic_partition)
    for fetch in pending:
        fetchable.discard(fetch.topic_partition)
    return fetchable
# Buggy code
def pull_image(image_tag_string, client):
    """Pull an image from a container registry using Docker
    Note: this function uses the Docker API to pull from a container
    registry and is not responsible for configuring what registry to use"""
    logger.debug('Attempting to pull image "%s"', image_tag_string)
    try:
        image = client.images.pull(image_tag_string)
        logger.debug('Image "%s" downloaded', image_tag_string)
        return image
    except (docker.errors.ImageNotFound, docker.errors.NotFound):
        logger.warning('No such image: "%s"', image_tag_string)
        return None


# Traceback (AttributeError)
$ tern report -o output.txt -i fossid-nginx:2020.2
2020-11-11 08:35:17,611 - DEBUG - __main__ - Starting...
2020-11-11 08:35:17,611 - DEBUG - prep - Setting up...
2020-11-11 08:35:18,060 - DEBUG - run - Starting analysis...
2020-11-11 08:35:18,154 - DEBUG - docker_api - Checking if image "fossid-nginx:2020.2" is available on disk...
2020-11-11 08:35:18,162 - DEBUG - docker_api - Attempting to pull image "fossid-nginx:2020.2"
2020-11-11 08:35:19,691 - WARNING - docker_api - No such image: "fossid-nginx:2020.2"
Traceback (most recent call last):
File "/home/nisha/terndev/bin/tern", line 10, in <module>
sys.exit(main())
File "/home/nisha/terndev/tern/tern/__main__.py", line 192, in main
do_main(args)
File "/home/nisha/terndev/tern/tern/__main__.py", line 95, in do_main
crun.execute_image(args)
File "/home/nisha/terndev/tern/tern/analyze/default/container/run.py", line 73, in execute_image
image_string = extract_image(args)
File "/home/nisha/terndev/tern/tern/analyze/default/container/run.py", line 32, in extract_image
image_attrs = docker_api.dump_docker_image(args.docker_image)
File "/home/nisha/terndev/tern/tern/load/docker_api.py", line 200, in dump_docker_image
if extract_image(image):
File "/home/nisha/terndev/tern/tern/load/docker_api.py", line 74, in extract_image
result = image_obj.save(chunk_size=2097152, named=True)
AttributeError: 'NoneType' object has no attribute 'save'

# Fixed code
def pull_image(image_tag_string, client):
    """Pull an image from a container registry using Docker
    Note: this function uses the Docker API to pull from a container
    registry and is not responsible for configuring what registry to use"""
    logger.debug('Attempting to pull image "%s"', image_tag_string)
    try:
        image = client.images.pull(image_tag_string)
        logger.debug('Image "%s" downloaded', image_tag_string)
        return image
    except (docker.errors.ImageNotFound, docker.errors.NotFound):
        logger.error('No such image: "%s"', image_tag_string)
        return None
# Buggy code
def dump_docker_image(image_tag):
    """Given an image and tag or image and digest, use the Docker API to get
    a container image representation into the working directory"""
    image_metadata = None
    # open up a client first
    # if this fails we cannot proceed further so we will exit
    client = check_docker_setup()
    image = get_docker_image(image_tag, client)
    # this should return whether the operation succeeded or not
    if extract_image(image):
        image_metadata = image.attrs
    # now the client can be closed
    close_client(client)
    return image_metadata


# Traceback (AttributeError)
$ tern report -o output.txt -i fossid-nginx:2020.2
2020-11-11 08:35:17,611 - DEBUG - __main__ - Starting...
2020-11-11 08:35:17,611 - DEBUG - prep - Setting up...
2020-11-11 08:35:18,060 - DEBUG - run - Starting analysis...
2020-11-11 08:35:18,154 - DEBUG - docker_api - Checking if image "fossid-nginx:2020.2" is available on disk...
2020-11-11 08:35:18,162 - DEBUG - docker_api - Attempting to pull image "fossid-nginx:2020.2"
2020-11-11 08:35:19,691 - WARNING - docker_api - No such image: "fossid-nginx:2020.2"
Traceback (most recent call last):
File "/home/nisha/terndev/bin/tern", line 10, in <module>
sys.exit(main())
File "/home/nisha/terndev/tern/tern/__main__.py", line 192, in main
do_main(args)
File "/home/nisha/terndev/tern/tern/__main__.py", line 95, in do_main
crun.execute_image(args)
File "/home/nisha/terndev/tern/tern/analyze/default/container/run.py", line 73, in execute_image
image_string = extract_image(args)
File "/home/nisha/terndev/tern/tern/analyze/default/container/run.py", line 32, in extract_image
image_attrs = docker_api.dump_docker_image(args.docker_image)
File "/home/nisha/terndev/tern/tern/load/docker_api.py", line 200, in dump_docker_image
if extract_image(image):
File "/home/nisha/terndev/tern/tern/load/docker_api.py", line 74, in extract_image
result = image_obj.save(chunk_size=2097152, named=True)
AttributeError: 'NoneType' object has no attribute 'save'

# Fixed code
def dump_docker_image(image_tag):
    """Given an image and tag or image and digest, use the Docker API to get
    a container image representation into the working directory"""
    image_metadata = None
    # open up a client first
    # if this fails we cannot proceed further so we will exit
    client = check_docker_setup()
    image = get_docker_image(image_tag, client)
    if image:
        if extract_image(image):
            image_metadata = image.attrs
    # now the client can be closed
    close_client(client)
    return image_metadata
# Buggy code
def get_git_toplevel(path):
    """Given a path, return the absolute path to the top level directory if it
    is in a git repository. Empty string will be returned if not.
    Path should be a path to a directory not to a file."""
    command = ["git", "rev-parse", "--show-toplevel"]
    path_to_toplevel = ""
    try:
        output = subprocess.check_output(  # nosec
            command, stderr=subprocess.DEVNULL, cwd=path
        )
        if isinstance(output, bytes):
            path_to_toplevel = output.decode("utf-8").split("\n").pop(0)
    except subprocess.CalledProcessError:
        logger.debug("Cannot find git repo toplevel, path is %s", path)
    return path_to_toplevel


# Traceback (FileNotFoundError)
Traceback (most recent call last):
File "/home/rjudge/ternenv/bin/tern", line 10, in <module>
sys.exit(main())
File "/home/rjudge/ternenv/tern/tern/__main__.py", line 201, in main
do_main(args)
File "/home/rjudge/ternenv/tern/tern/__main__.py", line 90, in do_main
run.execute_dockerfile(args)
File "/home/rjudge/ternenv/tern/tern/analyze/docker/run.py", line 176, in execute_dockerfile
output = dockerfile.create_locked_dockerfile(dfobj)
File "/home/rjudge/ternenv/tern/tern/analyze/docker/dockerfile.py", line 283, in create_locked_dockerfile
expand_add_command(dfobj)
File "/home/rjudge/ternenv/tern/tern/analyze/docker/dockerfile.py", line 270, in expand_add_command
dockerfile_path)
File "/home/rjudge/ternenv/tern/tern/analyze/docker/dockerfile.py", line 256, in find_git_info
comment_line = common.check_git_src(dockerfile_path)
File "/home/rjudge/ternenv/tern/tern/analyze/common.py", line 536, in check_git_src
path_to_toplevel = get_git_toplevel(dockerfile_folder_path)
File "/home/rjudge/ternenv/tern/tern/analyze/common.py", line 618, in get_git_toplevel
command, stderr=subprocess.DEVNULL, cwd=path)
File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
**kwargs).stdout
File "/usr/lib/python3.6/subprocess.py", line 423, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '': ''

# Fixed code
def get_git_toplevel(path):
    """Given a path, return the absolute path to the top level directory if it
    is in a git repository. Empty string will be returned if not.
    Path should be a path to a directory not to a file."""
    command = ["git", "rev-parse", "--show-toplevel"]
    path_to_toplevel = ""
    try:
        output = subprocess.check_output(  # nosec
            command, stderr=subprocess.DEVNULL, cwd=path
        )
        if isinstance(output, bytes):
            path_to_toplevel = output.decode("utf-8").split("\n").pop(0)
    except (subprocess.CalledProcessError, FileNotFoundError):
        logger.debug("Cannot find git repo toplevel, path is %s", path)
    return path_to_toplevel
# Buggy code
def close_client():
    """End docker interactions by closing the client. This is meant to be
    used after analysis is done"""
    try:
        client.close()
    except requests.exceptions.ConnectionError:
        # it should either already be closed or docker is not setup
        # either way, the socket is closed
        pass


# Traceback (AttributeError)
2020-04-08 09:28:59,030 - DEBUG - run - Teardown...
Traceback (most recent call last):
File "/home/rjudge/ternenv/bin/tern", line 10, in <module>
sys.exit(main())
File "/home/rjudge/ternenv/tern/tern/__main__.py", line 201, in main
do_main(args)
File "/home/rjudge/ternenv/tern/tern/__main__.py", line 113, in do_main
run.execute_docker_image(args)
File "/home/rjudge/ternenv/tern/tern/analyze/docker/run.py", line 99, in execute_docker_image
report.teardown()
File "/home/rjudge/ternenv/tern/tern/report/report.py", line 66, in teardown
container.close_client()
File "/home/rjudge/ternenv/tern/tern/analyze/docker/container.py", line 190, in close_client
client.close()
AttributeError: 'NoneType' object has no attribute 'close'

# Fixed code
def close_client():
    """End docker interactions by closing the client. This is meant to be
    used after analysis is done"""
    try:
        client.close()
    except (AttributeError, requests.exceptions.ConnectionError):
        # it should either already be closed, no socker is in use,
        # or docker is not setup -- either way, the socket is closed
        pass
# Buggy code
def pull_image(image_tag_string):
    """Try to pull an image from Dockerhub"""
    logger.debug('Attempting to pull image "%s"', image_tag_string)
    try:
        image = client.images.pull(image_tag_string)
        logger.debug('Image "%s" downloaded', image_tag_string)
        return image
    except docker.errors.ImageNotFound:
        logger.warning('No such image: "%s"', image_tag_string)
        return None


# Traceback (requests.exceptions.HTTPError)
2020-03-26 15:05:54,287 - DEBUG - container - Checking if image "photon:broken" is available on disk...
2020-03-26 15:05:54,290 - DEBUG - container - Attempting to pull image "photon:broken"
Traceback (most recent call last):
File "/home/rjudge/ternenv/lib/python3.6/site-packages/docker/api/client.py", line 261, in _raise_for_status
response.raise_for_status()
File "/home/rjudge/ternenv/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http+docker://localhost/v1.35/images/create?tag=broken&amp;fromImage=photon

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/rjudge/ternenv/bin/tern", line 10, in <module>
sys.exit(main())
File "/home/rjudge/ternenv/tern/tern/__main__.py", line 201, in main
do_main(args)
File "/home/rjudge/ternenv/tern/tern/__main__.py", line 90, in do_main
run.execute_dockerfile(args)
File "/home/rjudge/ternenv/tern/tern/analyze/docker/run.py", line 150, in execute_dockerfile
base_image = report.load_base_image()
File "/home/rjudge/ternenv/tern/tern/report/report.py", line 95, in load_base_image
if container.pull_image(base_image.repotag) is None:
File "/home/rjudge/ternenv/tern/tern/analyze/docker/container.py", line 91, in pull_image
image = client.images.pull(image_tag_string)
File "/home/rjudge/ternenv/lib/python3.6/site-packages/docker/models/images.py", line 445, in pull
repository, tag=tag, stream=True, **kwargs
File "/home/rjudge/ternenv/lib/python3.6/site-packages/docker/api/image.py", line 415, in pull
self._raise_for_status(response)
File "/home/rjudge/ternenv/lib/python3.6/site-packages/docker/api/client.py", line 263, in _raise_for_status
raise create_api_error_from_http_exception(e)
File "/home/rjudge/ternenv/lib/python3.6/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation)
docker.errors.NotFound: 404 Client Error: Not Found ("manifest for photon:broken not found: manifest unknown: manifest unknown")

# Fixed code
def pull_image(image_tag_string):
    """Try to pull an image from Dockerhub"""
    logger.debug('Attempting to pull image "%s"', image_tag_string)
    try:
        image = client.images.pull(image_tag_string)
        logger.debug('Image "%s" downloaded', image_tag_string)
        return image
    except (docker.errors.ImageNotFound, docker.errors.NotFound):
        logger.warning('No such image: "%s"', image_tag_string)
        return None
# Buggy code
def prep_rootfs(rootfs_dir):
    """Mount required filesystems in the rootfs directory"""
    rootfs_path = os.path.abspath(rootfs_dir)
    try:
        root_command(mount_proc, os.path.join(rootfs_path, "proc"))
        root_command(mount_sys, os.path.join(rootfs_path, "sys"))
        root_command(mount_dev, os.path.join(rootfs_path, "dev"))
        root_command(host_dns, os.path.join(rootfs_path, constants.resolv_path[1:]))
    except subprocess.CalledProcessError as error:
        logger.error("%s", error.output)
        raise


# Traceback (subprocess.CalledProcessError)
2020-02-16 17:00:00,058 - ERROR - rootfs - b'mount: /home/oc37ejuc/.tern/temp/mergedir/proc: mount point does not exist.\n'
Traceback (most recent call last):
File "/home/oc37ejuc/ternenv/bin/tern", line 11, in <module>
sys.exit(main())
File "/home/oc37ejuc/ternenv/lib/python3.6/site-packages/tern/__main__.py", line 170, in main
do_main(args)
File "/home/oc37ejuc/ternenv/lib/python3.6/site-packages/tern/__main__.py", line 93, in do_main
run.execute_docker_image(args)
File "/home/oc37ejuc/ternenv/lib/python3.6/site-packages/tern/analyze/docker/run.py", line 88, in execute_docker_image
analyze(full_image, args)
File "/home/oc37ejuc/ternenv/lib/python3.6/site-packages/tern/analyze/docker/run.py", line 67, in analyze
analyze_docker_image(image_obj, args.redo, is_dockerfile)
File "/home/oc37ejuc/ternenv/lib/python3.6/site-packages/tern/analyze/docker/analyze.py", line 37, in analyze_docker_image
shell = analyze_first_layer(image_obj, master_list, redo)
File "/home/oc37ejuc/ternenv/lib/python3.6/site-packages/tern/analyze/docker/analyze.py", line 98, in analyze_first_layer
rootfs.prep_rootfs(target)
File "/home/oc37ejuc/ternenv/lib/python3.6/site-packages/tern/utils/rootfs.py", line 177, in prep_rootfs
root_command(mount_proc, os.path.join(rootfs_path, 'proc'))
File "/home/oc37ejuc/ternenv/lib/python3.6/site-packages/tern/utils/rootfs.py", line 79, in root_command
1, cmd=full_cmd, output=error)
subprocess.CalledProcessError: Command '['sudo', 'mount', '-t', 'proc', '/proc', '/home/oc37ejuc/.tern/temp/mergedir/proc']' returned non-zero exit status 1.

# Fixed code
def prep_rootfs(rootfs_dir):
    """Mount required filesystems in the rootfs directory"""
    rootfs_path = os.path.abspath(rootfs_dir)
    proc_path = os.path.join(rootfs_path, "proc")
    sys_path = os.path.join(rootfs_path, "sys")
    dev_path = os.path.join(rootfs_path, "dev")
    if not os.path.exists(proc_path):
        os.mkdir(proc_path)
    if not os.path.exists(sys_path):
        os.mkdir(sys_path)
    if not os.path.exists(dev_path):
        os.mkdir(dev_path)
    try:
        root_command(mount_proc, os.path.join(rootfs_path, "proc"))
        root_command(mount_sys, os.path.join(rootfs_path, "sys"))
        root_command(mount_dev, os.path.join(rootfs_path, "dev"))
        root_command(host_dns, os.path.join(rootfs_path, constants.resolv_path[1:]))
    except subprocess.CalledProcessError as error:
        logger.error("%s", error.output)
        raise
# Buggy code
def load():
    """Load the cache"""
    global cache

    # Do not try to populate the cache if there is no cache available
    if not os.path.exists(os.path.join(get_top_dir(), cache_file)):
        return

    with open(os.path.join(get_top_dir(), cache_file)) as f:
        cache = yaml.safe_load(f)


# Traceback (subprocess.CalledProcessError)
docker build -t ternd .
./docker_run.sh workdir ternd "report -i golang:alpine"
-------------------------OUTPUT-------------------------
Traceback (most recent call last):
File "/usr/bin/tern", line 8, in <module>
sys.exit(main())
File "/usr/lib/python3.7/site-packages/tern/__main__.py", line 167, in main
do_main(args)
File "/usr/lib/python3.7/site-packages/tern/__main__.py", line 90, in do_main
run.execute_docker_image(args)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/run.py", line 88, in execute_docker_image
analyze(full_image, args)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/run.py", line 67, in analyze
analyze_docker_image(image_obj, args.redo, is_dockerfile)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/analyze.py", line 39, in analyze_docker_image
analyze_subsequent_layers(image_obj, shell, master_list, redo)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/analyze.py", line 133, in analyze_subsequent_layers
target = mount_overlay_fs(image_obj, curr_layer)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/analyze.py", line 178, in mount_overlay_fs
target = rootfs.mount_diff_layers(tar_layers)
File "/usr/lib/python3.7/site-packages/tern/utils/rootfs.py", line 196, in mount_diff_layers
root_command(union_mount, args, merge_dir_path)
File "/usr/lib/python3.7/site-packages/tern/utils/rootfs.py", line 66, in root_command
1, cmd=full_cmd, output=error)
subprocess.CalledProcessError: Command '['mount', '-t', 'overlay', 'overlay', '-o', 'lowerdir=/root/.tern/temp/8e635d6264340a45901f63d2a18ea5bc8c680919e07191e4ef276860952d0399/contents,upperdir=/root/.tern/temp/1332c5c5bbaa26b26053d13d13b81dd2f523a2217e01f6edfe38fe107c091859/contents,workdir=/root/.tern/temp/workdir', '/root/.tern/temp/mergedir']' returned non-zero exit status 1.
Traceback (most recent call last):
File "ci/test_files_touched.py", line 130, in <module>
subprocess.check_output(t, shell=True)  # nosec
File "/opt/circleci/.pyenv/versions/3.6.5/lib/python3.6/subprocess.py", line 336, in check_output
**kwargs).stdout
File "/opt/circleci/.pyenv/versions/3.6.5/lib/python3.6/subprocess.py", line 418, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command './docker_run.sh workdir ternd "report -i golang:alpine"' returned non-zero exit status 1.
Exited with code 1

# Fixed code
def load():
    """Load the cache"""
    global cache

    # Do not try to populate the cache if there is no cache available
    if not os.path.exists(os.path.join(rootfs.mount_dir, cache_file)):
        return

    with open(os.path.join(rootfs.mount_dir, cache_file)) as f:
        cache = yaml.safe_load(f)
# Buggy code
def save():
    """Save the cache to the cache file"""
    with open(os.path.join(get_top_dir(), cache_file), "w") as f:
        yaml.dump(cache, f, default_flow_style=False)


# Traceback (subprocess.CalledProcessError)
docker build -t ternd .
./docker_run.sh workdir ternd "report -i golang:alpine"
-------------------------OUTPUT-------------------------
Traceback (most recent call last):
File "/usr/bin/tern", line 8, in <module>
sys.exit(main())
File "/usr/lib/python3.7/site-packages/tern/__main__.py", line 167, in main
do_main(args)
File "/usr/lib/python3.7/site-packages/tern/__main__.py", line 90, in do_main
run.execute_docker_image(args)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/run.py", line 88, in execute_docker_image
analyze(full_image, args)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/run.py", line 67, in analyze
analyze_docker_image(image_obj, args.redo, is_dockerfile)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/analyze.py", line 39, in analyze_docker_image
analyze_subsequent_layers(image_obj, shell, master_list, redo)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/analyze.py", line 133, in analyze_subsequent_layers
target = mount_overlay_fs(image_obj, curr_layer)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/analyze.py", line 178, in mount_overlay_fs
target = rootfs.mount_diff_layers(tar_layers)
File "/usr/lib/python3.7/site-packages/tern/utils/rootfs.py", line 196, in mount_diff_layers
root_command(union_mount, args, merge_dir_path)
File "/usr/lib/python3.7/site-packages/tern/utils/rootfs.py", line 66, in root_command
1, cmd=full_cmd, output=error)
subprocess.CalledProcessError: Command '['mount', '-t', 'overlay', 'overlay', '-o', 'lowerdir=/root/.tern/temp/8e635d6264340a45901f63d2a18ea5bc8c680919e07191e4ef276860952d0399/contents,upperdir=/root/.tern/temp/1332c5c5bbaa26b26053d13d13b81dd2f523a2217e01f6edfe38fe107c091859/contents,workdir=/root/.tern/temp/workdir', '/root/.tern/temp/mergedir']' returned non-zero exit status 1.
Traceback (most recent call last):
File "ci/test_files_touched.py", line 130, in <module>
subprocess.check_output(t, shell=True)  # nosec
File "/opt/circleci/.pyenv/versions/3.6.5/lib/python3.6/subprocess.py", line 336, in check_output
**kwargs).stdout
File "/opt/circleci/.pyenv/versions/3.6.5/lib/python3.6/subprocess.py", line 418, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command './docker_run.sh workdir ternd "report -i golang:alpine"' returned non-zero exit status 1.
Exited with code 1

# Fixed code
def save():
    """Save the cache to the cache file"""
    with open(os.path.join(rootfs.mount_dir, cache_file), "w") as f:
        yaml.dump(cache, f, default_flow_style=False)
# Buggy code
def clear():
    """Empty the cache - don't use unless you really have to"""
    global cache
    cache = {}
    with open(os.path.join(get_top_dir(), cache_file), "w") as f:
        yaml.dump(cache, f, default_flow_style=False)


# Traceback (subprocess.CalledProcessError)
docker build -t ternd .
./docker_run.sh workdir ternd "report -i golang:alpine"
-------------------------OUTPUT-------------------------
Traceback (most recent call last):
File "/usr/bin/tern", line 8, in <module>
sys.exit(main())
File "/usr/lib/python3.7/site-packages/tern/__main__.py", line 167, in main
do_main(args)
File "/usr/lib/python3.7/site-packages/tern/__main__.py", line 90, in do_main
run.execute_docker_image(args)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/run.py", line 88, in execute_docker_image
analyze(full_image, args)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/run.py", line 67, in analyze
analyze_docker_image(image_obj, args.redo, is_dockerfile)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/analyze.py", line 39, in analyze_docker_image
analyze_subsequent_layers(image_obj, shell, master_list, redo)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/analyze.py", line 133, in analyze_subsequent_layers
target = mount_overlay_fs(image_obj, curr_layer)
File "/usr/lib/python3.7/site-packages/tern/analyze/docker/analyze.py", line 178, in mount_overlay_fs
target = rootfs.mount_diff_layers(tar_layers)
File "/usr/lib/python3.7/site-packages/tern/utils/rootfs.py", line 196, in mount_diff_layers
root_command(union_mount, args, merge_dir_path)
File "/usr/lib/python3.7/site-packages/tern/utils/rootfs.py", line 66, in root_command
1, cmd=full_cmd, output=error)
subprocess.CalledProcessError: Command '['mount', '-t', 'overlay', 'overlay', '-o', 'lowerdir=/root/.tern/temp/8e635d6264340a45901f63d2a18ea5bc8c680919e07191e4ef276860952d0399/contents,upperdir=/root/.tern/temp/1332c5c5bbaa26b26053d13d13b81dd2f523a2217e01f6edfe38fe107c091859/contents,workdir=/root/.tern/temp/workdir', '/root/.tern/temp/mergedir']' returned non-zero exit status 1.
Traceback (most recent call last):
File "ci/test_files_touched.py", line 130, in <module>
subprocess.check_output(t, shell=True)  # nosec
File "/opt/circleci/.pyenv/versions/3.6.5/lib/python3.6/subprocess.py", line 336, in check_output
**kwargs).stdout
File "/opt/circleci/.pyenv/versions/3.6.5/lib/python3.6/subprocess.py", line 418, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command './docker_run.sh workdir ternd "report -i golang:alpine"' returned non-zero exit status 1.
Exited with code 1

# Fixed code
def clear():
    """Empty the cache - don't use unless you really have to"""
    global cache
    cache = {}
    with open(os.path.join(rootfs.mount_dir, cache_file), "w") as f:
        yaml.dump(cache, f, default_flow_style=False)