aboutcode-org / aboutcode-org/scancode-toolkit

scancode crash when using directory with --from-json

未关闭
#3,592 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
Python
星标
2.6k
派生
791
平均合并
1 天 12 小时
30 天内合并 PR
5

描述

### Description

Related to #3588, #3589, #3590 and #3591

When using `--from-json` it is possible to pass directories instead of regular files, resulting in a crash.

### How To Reproduce

```
$ ./scancode --from-json /tmp/bla --yaml /tmp/scancode.yaml
Setup plugins...
Collect file inventory...
Removing temporary files...done.
Usage: scancode [OPTIONS] ...
Try the 'scancode --help' option for help on options and arguments.

Error: Invalid value: ERROR: failed to collect codebase at: '/tmp/bla'
Traceback (most recent call last):
File "/home/armijn/git/scancode-toolkit/venv/lib/python3.10/site-packages/commoncode/resource.py", line 1685, in _get_scan_data_helper
return json.loads(location)
File "/usr/lib64/python3.10/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/armijn/git/scancode-toolkit/src/scancode/cli.py", line 844, in run_scan
codebase = codebase_class(
File "/home/armijn/git/scancode-toolkit/venv/lib/python3.10/site-packages/commoncode/resource.py", line 1676, in __init__
scan_data = self._get_scan_data(location)
File "/home/armijn/git/scancode-toolkit/venv/lib/python3.10/site-packages/commoncode/resource.py", line 1736, in _get_scan_data
return self._get_scan_data_helper(location)
File "/home/armijn/git/scancode-toolkit/venv/lib/python3.10/site-packages/commoncode/resource.py", line 1689, in _get_scan_data_helper
with open(location) as f:
IsADirectoryError: [Errno 21] Is a directory: '/tmp/bla'

```

### System configuration

> For bug reports, it really helps us to know:

* What OS are you running on? (Windows/MacOS/Linux)
* What version of scancode-toolkit was used to generate the scan file?
* What installation method was used to install/run scancode? (pip/source download/other)

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。