Skip to content

Commit 762b283

Browse files
authored
Merge pull request #6 from jayvdb/fix-pkginfo
_pkginfo: Improve error handling
2 parents b5762b1 + 7d21e4f commit 762b283

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

dephell_setuptools/_pkginfo.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ def content(self) -> Dict[str, Any]:
1717
cmd = ['pkginfo', '--json', str(self.path)]
1818
result = subprocess.run(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
1919
if result.returncode != 0:
20-
raise RuntimeError(result.stderr.decode().split('\n')[-1])
21-
content = json.loads(result.stdout.decode())
20+
msg_lines = result.stderr.decode().rstrip().split('\n')
21+
raise RuntimeError(msg_lines[-1] if msg_lines else 'Unknown error')
22+
stdout = result.stdout.decode()
23+
if not stdout:
24+
return {}
25+
26+
try:
27+
content = json.loads(stdout)
28+
except json.decoder.JSONDecodeError:
29+
return {}
30+
2231
return self._clean(content)

0 commit comments

Comments
 (0)