Skip to content

Commit

Permalink
better errors for pkg-list files loading (#16685)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Jul 17, 2024
1 parent 55f017f commit f0ea1a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion conan/api/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fnmatch
import json
import os
from json import JSONDecodeError

from conans.client.graph.graph import RECIPE_EDITABLE, RECIPE_CONSUMER, RECIPE_PLATFORM, \
RECIPE_VIRTUAL, BINARY_SKIP, BINARY_MISSING, BINARY_INVALID
Expand Down Expand Up @@ -73,7 +74,12 @@ def merge(self, other):

@staticmethod
def load(file):
content = json.loads(load(file))
try:
content = json.loads(load(file))
except JSONDecodeError as e:
raise ConanException(f"Package list file invalid JSON: {file}\n{e}")
except Exception as e:
raise ConanException(f"Package list file missing or broken: {file}\n{e}")
result = {}
for remote, pkglist in content.items():
if "error" in pkglist:
Expand Down
9 changes: 9 additions & 0 deletions test/integration/command_v2/test_combined_pkglist_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ def test_graph_2_pkg_list_remotes(self):
settings = rev["packages"]["9e186f6d94c008b544af1569d1a6368d8339efc5"]["info"]["settings"]
assert settings == {"build_type": "Debug"}

def test_pkglist_file_error(self):
# This can happen when reusing the same file in input and output
c = TestClient(light=True)
c.run("pkglist merge -l mylist.json", assert_error=True)
assert "ERROR: Package list file missing or broken:" in c.out
c.save({"mylist.json": ""})
c.run("pkglist merge -l mylist.json", assert_error=True)
assert "ERROR: Package list file invalid JSON:" in c.out


class TestDownloadUpload:
@pytest.fixture()
Expand Down

0 comments on commit f0ea1a5

Please sign in to comment.