Skip to content

Commit

Permalink
Throw a differente exception if transition ID is set but index is not
Browse files Browse the repository at this point in the history
  • Loading branch information
makortel committed Sep 4, 2020
1 parent 771ba07 commit c62a716
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
10 changes: 6 additions & 4 deletions FWCore/Framework/interface/EventSetupRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ namespace edm {
template <template <typename> typename H, typename T, typename R>
H<T> getHandleImpl(ESGetToken<T, R> const& iToken) const {
if UNLIKELY (not iToken.isInitialized()) {
std::rethrow_exception(makeInvalidTokenException(this->key(), DataKey::makeTypeTag<T>()));
std::rethrow_exception(makeUninitializedTokenException(this->key(), DataKey::makeTypeTag<T>()));
}
if UNLIKELY (iToken.transitionID() != transitionID()) {
throwWrongTransitionID();
Expand Down Expand Up @@ -255,8 +255,9 @@ namespace edm {
template <template <typename> typename H, typename T, typename R>
H<T> invalidTokenHandle(ESGetToken<T, R> const& iToken) const {
auto const key = this->key();
return H<T>{
makeESHandleExceptionFactory([key] { return makeInvalidTokenException(key, DataKey::makeTypeTag<T>()); })};
return H<T>{makeESHandleExceptionFactory([key, transitionID = iToken.transitionID()] {
return makeInvalidTokenException(key, DataKey::makeTypeTag<T>(), transitionID);
})};
}

template <template <typename> typename H, typename T, typename R>
Expand All @@ -273,7 +274,8 @@ namespace edm {
ComponentDescription const*& iDesc,
bool iTransientAccessOnly) const;

static std::exception_ptr makeInvalidTokenException(EventSetupRecordKey const&, TypeTag const&);
static std::exception_ptr makeUninitializedTokenException(EventSetupRecordKey const&, TypeTag const&);
static std::exception_ptr makeInvalidTokenException(EventSetupRecordKey const&, TypeTag const&, unsigned int);
void throwWrongTransitionID() const;
static void throwCalledGetWithoutToken(const char* iTypeName, const char* iLabel);
// ---------- member data --------------------------------
Expand Down
15 changes: 13 additions & 2 deletions FWCore/Framework/src/EventSetupRecord.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ namespace edm {
iException.addContext(ost.str());
}

std::exception_ptr EventSetupRecord::makeInvalidTokenException(EventSetupRecordKey const& iRecordKey,
TypeTag const& iDataKey) {
std::exception_ptr EventSetupRecord::makeUninitializedTokenException(EventSetupRecordKey const& iRecordKey,
TypeTag const& iDataKey) {
cms::Exception ex("InvalidESGetToken");
ex << "Attempted to get data using an invalid token of type ESGetToken<" << iDataKey.name() << ","
<< iRecordKey.name()
Expand All @@ -80,6 +80,17 @@ namespace edm {
return std::make_exception_ptr(ex);
}

std::exception_ptr EventSetupRecord::makeInvalidTokenException(EventSetupRecordKey const& iRecordKey,
TypeTag const& iDataKey,
unsigned int iTransitionID) {
cms::Exception ex("InvalidESGetToken");
ex << "Attempted to get data using an invalid token of type ESGetToken<" << iDataKey.name() << ","
<< iRecordKey.name() << "> that had transition ID set (" << iTransitionID
<< ") but not the index.\n"
"This should not happen, please contact core framework developers.";
return std::make_exception_ptr(ex);
}

void EventSetupRecord::throwWrongTransitionID() const {
cms::Exception ex("ESGetTokenWrongTransition");
ex << "The transition ID stored in the ESGetToken does not match the\n"
Expand Down

0 comments on commit c62a716

Please sign in to comment.