diff --git a/news/2358.bugfix.md b/news/2358.bugfix.md new file mode 100644 index 0000000000..75ce4f75c3 --- /dev/null +++ b/news/2358.bugfix.md @@ -0,0 +1 @@ +Improve the error message when a specific package can't be found in the lockfile. diff --git a/src/pdm/models/repositories.py b/src/pdm/models/repositories.py index 6fd07fbc36..70374e342e 100644 --- a/src/pdm/models/repositories.py +++ b/src/pdm/models/repositories.py @@ -552,7 +552,14 @@ def _identify_candidate(self, candidate: Candidate) -> CandidateKey: ) def _get_dependencies_from_lockfile(self, candidate: Candidate) -> CandidateInfo: - return self.candidate_info[self._identify_candidate(candidate)] + err = ( + f"Missing package {candidate.identify()} from the lockfile, " + "the lockfile may be broken. Run `pdm update` to fix it." + ) + try: + return self.candidate_info[self._identify_candidate(candidate)] + except KeyError as e: # pragma: no cover + raise CandidateNotFound(err) from e def dependency_generators(self) -> Iterable[Callable[[Candidate], CandidateInfo]]: return (