diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0c45dcc2af..352a49e92c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -27,7 +27,7 @@ Since last release * Adds support for Cython3 (#1636) * Adds TotalInvTracker, which allows an inventory cap to be set for multiple resource buffers, and is now required for material buy policy (#1646) * AddMutalReqs and AddReciepe functions and exclusive bids in python API of DRE (#1584) -* Created Package class and optional declaration of packages in input files (#1673), package id is a member of resources (materials/products) (#1675) +* Created Package class and optional declaration of packages in input files (#1673, #1699), package id is a member of resources (materials/products) (#1675) * CI support for Rocky Linux (#1691) **Changed:** diff --git a/src/context.cc b/src/context.cc index cea27a6e0b..30294c93e1 100644 --- a/src/context.cc +++ b/src/context.cc @@ -211,6 +211,9 @@ Package::Ptr Context::GetPackageByName(std::string name) { } Package::Ptr Context::GetPackageById(int id) { + if (id < 0) { + throw ValueError("Invalid package id " + std::to_string(id)); + } // iterate through the list of packages to get the one package with the correct id std::map::iterator it; for (it = packages_.begin(); it != packages_.end(); ++it) { @@ -218,6 +221,7 @@ Package::Ptr Context::GetPackageById(int id) { return it->second; } } + throw ValueError("Invalid package id " + std::to_string(id)); } void Context::InitSim(SimInfo si) {