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

better errors for pkg-list files loading #16685

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
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
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