Skip to content

Commit daddb67

Browse files
committed
[ntuple] improve error message in ReconcileIntegralField()
Use the type trace report to help identify the violating subfield in a field hiararchy.
1 parent ee8a207 commit daddb67

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

tree/ntuple/src/RField.cxx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ void ROOT::RCardinalityField::ReconcileOnDiskField(const RNTupleDescriptor &desc
8383
if (fieldDesc.GetStructure() == ENTupleStructure::kPlain) {
8484
if (fieldDesc.GetTypeName().rfind("ROOT::RNTupleCardinality<", 0) != 0) {
8585
throw RException(R__FAIL("RCardinalityField " + GetQualifiedFieldName() +
86-
" expects an on-disk leaf field of the same type"));
86+
" expects an on-disk leaf field of the same type\n" +
87+
Internal::GetTypeTraceReport(*this, desc)));
8788
}
8889
} else if (fieldDesc.GetStructure() != ENTupleStructure::kCollection) {
89-
throw RException(R__FAIL("invalid on-disk structural role for RCardinalityField " + GetQualifiedFieldName()));
90+
throw RException(R__FAIL("invalid on-disk structural role for RCardinalityField " + GetQualifiedFieldName() +
91+
"\n" + Internal::GetTypeTraceReport(*this, desc)));
9092
}
9193
}
9294

@@ -124,7 +126,7 @@ void ROOT::RSimpleField<T>::ReconcileIntegralField(const RNTupleDescriptor &desc
124126
if (std::find(std::begin(gIntegralTypeNames), std::end(gIntegralTypeNames), fieldDesc.GetTypeName()) ==
125127
std::end(gIntegralTypeNames)) {
126128
throw RException(R__FAIL("unexpected on-disk type name '" + fieldDesc.GetTypeName() + "' for field of type '" +
127-
GetTypeName() + "'"));
129+
GetTypeName() + "'\n" + Internal::GetTypeTraceReport(*this, desc)));
128130
}
129131
}
130132

@@ -136,7 +138,7 @@ void ROOT::RSimpleField<T>::ReconcileFloatingPointField(const RNTupleDescriptor
136138
const RFieldDescriptor &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
137139
if (!(fieldDesc.GetTypeName() == "float" || fieldDesc.GetTypeName() == "double")) {
138140
throw RException(R__FAIL("unexpected on-disk type name '" + fieldDesc.GetTypeName() + "' for field of type '" +
139-
GetTypeName() + "'"));
141+
GetTypeName() + "'\n" + Internal::GetTypeTraceReport(*this, desc)));
140142
}
141143
}
142144

tree/ntuple/src/RFieldBase.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ ROOT::RFieldBase::EnsureMatchingOnDiskField(const RNTupleDescriptor &desc, std::
10461046
if (diffBits & kDiffNRepetitions) {
10471047
errMsg << " repetition count " << GetNRepetitions() << " vs. " << fieldDesc.GetNRepetitions() << ";";
10481048
}
1049-
return R__FAIL(errMsg.str());
1049+
return R__FAIL(errMsg.str() + "\n" + Internal::GetTypeTraceReport(*this, desc));
10501050
}
10511051

10521052
ROOT::RResult<void> ROOT::RFieldBase::EnsureMatchingTypePrefix(const RNTupleDescriptor &desc,
@@ -1057,7 +1057,8 @@ ROOT::RResult<void> ROOT::RFieldBase::EnsureMatchingTypePrefix(const RNTupleDesc
10571057
if (fieldDesc.GetTypeName().rfind(p, 0) == 0)
10581058
return RResult<void>::Success();
10591059
}
1060-
return R__FAIL("incompatible type " + fieldDesc.GetTypeName() + " for field " + GetQualifiedFieldName());
1060+
return R__FAIL("incompatible type " + fieldDesc.GetTypeName() + " for field " + GetQualifiedFieldName() + "\n" +
1061+
Internal::GetTypeTraceReport(*this, desc));
10611062
}
10621063

10631064
std::uint32_t ROOT::RFieldBase::CompareOnDiskField(const RFieldDescriptor &fieldDesc, std::uint32_t ignoreBits) const

tree/ntuple/src/RFieldMeta.cxx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,9 @@ void ROOT::RPairField::ReconcileOnDiskField(const RNTupleDescriptor &desc)
690690
const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
691691
const auto nOnDiskSubfields = fieldDesc.GetLinkIds().size();
692692
if (nOnDiskSubfields != 2) {
693-
throw ROOT::RException(
694-
R__FAIL("invalid number of on-disk subfields for std::pair " + std::to_string(nOnDiskSubfields)));
693+
throw ROOT::RException(R__FAIL("invalid number of on-disk subfields for std::pair " +
694+
std::to_string(nOnDiskSubfields) + "\n" +
695+
Internal::GetTypeTraceReport(*this, desc)));
695696
}
696697
}
697698

@@ -1239,7 +1240,8 @@ void ROOT::RTupleField::ReconcileOnDiskField(const RNTupleDescriptor &desc)
12391240
const auto nSubfields = fSubfields.size();
12401241
if (nOnDiskSubfields != nSubfields) {
12411242
throw ROOT::RException(R__FAIL("invalid number of on-disk subfields for std::tuple " +
1242-
std::to_string(nOnDiskSubfields) + " vs. " + std::to_string(nSubfields)));
1243+
std::to_string(nOnDiskSubfields) + " vs. " + std::to_string(nSubfields) + "\n" +
1244+
Internal::GetTypeTraceReport(*this, desc)));
12431245
}
12441246
}
12451247

@@ -1398,7 +1400,8 @@ void ROOT::RVariantField::ReconcileOnDiskField(const RNTupleDescriptor &desc)
13981400

13991401
const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
14001402
if (fSubfields.size() != fieldDesc.GetLinkIds().size()) {
1401-
throw RException(R__FAIL("number of variants on-disk do not match for " + GetQualifiedFieldName()));
1403+
throw RException(R__FAIL("number of variants on-disk do not match for " + GetQualifiedFieldName() + "\n" +
1404+
Internal::GetTypeTraceReport(*this, desc)));
14021405
}
14031406
}
14041407

tree/ntuple/src/RFieldSequenceContainer.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,8 @@ void ROOT::RArrayAsRVecField::ReconcileOnDiskField(const RNTupleDescriptor &desc
845845
.ThrowOnError();
846846
const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
847847
if (fieldDesc.GetTypeName().rfind("std::array<", 0) != 0) {
848-
throw RException(R__FAIL("RArrayAsRVecField " + GetQualifiedFieldName() + " expects an on-disk array field"));
848+
throw RException(R__FAIL("RArrayAsRVecField " + GetQualifiedFieldName() + " expects an on-disk array field\n" +
849+
Internal::GetTypeTraceReport(*this, desc)));
849850
}
850851
}
851852

0 commit comments

Comments
 (0)