Skip to content

Commit 63474d0

Browse files
Copilotjpfeuffer
andauthored
Add mandatory context message to Exception::InvalidSize (OpenMS#8437)
* Initial plan * Add mandatory context message parameter to Exception::InvalidSize Co-authored-by: jpfeuffer <8102638+jpfeuffer@users.noreply.github.com> * Fix Tutorial_Precursor.cpp to use updated InvalidSize constructor Co-authored-by: jpfeuffer <8102638+jpfeuffer@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jpfeuffer <8102638+jpfeuffer@users.noreply.github.com>
1 parent 5f33c34 commit 63474d0

15 files changed

Lines changed: 25 additions & 24 deletions

File tree

doc/code_examples/Tutorial_Precursor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int main(int argc, const char** argv)
3434
const vector<Precursor>& precursors = spectrum.getPrecursors();
3535

3636
// size check & throw exception if needed
37-
if (precursors.empty()) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, precursors.size());
37+
if (precursors.empty()) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, precursors.size(), "precursors vector must not be empty");
3838

3939
// get m/z and intensity of precursor
4040
double precursor_mz = precursors[0].getMZ();

src/openms/include/OpenMS/CONCEPT/Exception.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,14 @@ namespace OpenMS
268268
The constructor has an additional argument: the value of of the
269269
requested size.
270270
@param size the size causing the problem
271+
@param message context message explaining why the size is invalid
271272
272273
@ingroup Exceptions
273274
*/
274275
class OPENMS_DLLAPI InvalidSize : public BaseException
275276
{
276277
public:
277-
InvalidSize(const char* file, int line, const char* function, Size size = 0) noexcept;
278+
InvalidSize(const char* file, int line, const char* function, Size size, const std::string& message) noexcept;
278279
};
279280

280281

src/openms/source/ANALYSIS/DECHARGING/ILPDCWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ namespace OpenMS
157157

158158
if (pairs_clique_ordered.size() != pairs.size())
159159
{
160-
throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, pairs_clique_ordered.size() - pairs.size());
160+
throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, pairs_clique_ordered.size() - pairs.size(), "pairs_clique_ordered size does not match pairs size");
161161
}
162162
/* swap pairs, such that edges are order by cliques (so we can make clean cuts) */
163163
pairs.swap(pairs_clique_ordered);

src/openms/source/ANALYSIS/OPENSWATH/TargetedSpectraExtractor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ namespace OpenMS
497497
scored_spectra.resize(annotated_spectra.size());
498498
if (compute_features && scored_spectra.size() != features.size())
499499
{
500-
throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
500+
throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, scored_spectra.size(), "scored_spectra size does not match features size");
501501
}
502502
for (Size i = 0; i < annotated_spectra.size(); ++i)
503503
{
@@ -587,7 +587,7 @@ namespace OpenMS
587587
{
588588
if (compute_features && scored_spectra.size() != features.size())
589589
{
590-
throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
590+
throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, scored_spectra.size(), "scored_spectra size does not match features size");
591591
}
592592
std::map<std::string,UInt> transition_best_spec;
593593
for (UInt i = 0; i < scored_spectra.size(); ++i)
@@ -774,7 +774,7 @@ namespace OpenMS
774774
{
775775
if (spectra.size() != features.size())
776776
{
777-
throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
777+
throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, spectra.size(), "spectra size does not match features size");
778778
}
779779

780780
std::vector<Size> no_matches_idx; // to keep track of those features without a match

src/openms/source/CHEMISTRY/TheoreticalSpectrumGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,8 @@ namespace OpenMS
718718
{
719719
case Residue::AIon: intensity = a_intensity_; break;
720720
case Residue::BIon: intensity = b_intensity_; break;
721-
case Residue::CIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1); intensity = c_intensity_; break;
722-
case Residue::XIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1); intensity = x_intensity_; break;
721+
case Residue::CIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1, "peptide must have at least 2 residues for c-ion generation"); intensity = c_intensity_; break;
722+
case Residue::XIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1, "peptide must have at least 2 residues for x-ion generation"); intensity = x_intensity_; break;
723723
case Residue::YIon: intensity = y_intensity_; break;
724724
case Residue::ZIon: intensity = z_intensity_; break;
725725
// TODO use different intensities?

src/openms/source/CHEMISTRY/TheoreticalSpectrumGeneratorXLMS.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ namespace OpenMS
251251
{
252252
case Residue::AIon: intensity = a_intensity_; break;
253253
case Residue::BIon: intensity = b_intensity_; break;
254-
case Residue::CIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1); intensity = c_intensity_; break;
255-
case Residue::XIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1); intensity = x_intensity_; break;
254+
case Residue::CIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1, "peptide must have at least 2 residues for c-ion generation"); intensity = c_intensity_; break;
255+
case Residue::XIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1, "peptide must have at least 2 residues for x-ion generation"); intensity = x_intensity_; break;
256256
case Residue::YIon: intensity = y_intensity_; break;
257257
case Residue::ZIon: intensity = z_intensity_; break;
258258
default: break;
@@ -456,8 +456,8 @@ namespace OpenMS
456456
{
457457
case Residue::AIon: intensity = a_intensity_; break;
458458
case Residue::BIon: intensity = b_intensity_; break;
459-
case Residue::CIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1); intensity = c_intensity_; break;
460-
case Residue::XIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1); intensity = x_intensity_; break;
459+
case Residue::CIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1, "peptide must have at least 2 residues for c-ion generation"); intensity = c_intensity_; break;
460+
case Residue::XIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1, "peptide must have at least 2 residues for x-ion generation"); intensity = x_intensity_; break;
461461
case Residue::YIon: intensity = y_intensity_; break;
462462
case Residue::ZIon: intensity = z_intensity_; break;
463463
default: break;
@@ -1005,8 +1005,8 @@ namespace OpenMS
10051005
{
10061006
case Residue::AIon: intensity = a_intensity_; break;
10071007
case Residue::BIon: intensity = b_intensity_; break;
1008-
case Residue::CIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1); intensity = c_intensity_; break;
1009-
case Residue::XIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1); intensity = x_intensity_; break;
1008+
case Residue::CIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1, "peptide must have at least 2 residues for c-ion generation"); intensity = c_intensity_; break;
1009+
case Residue::XIon: if (peptide.size() < 2) throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 1, "peptide must have at least 2 residues for x-ion generation"); intensity = x_intensity_; break;
10101010
case Residue::YIon: intensity = y_intensity_; break;
10111011
case Residue::ZIon: intensity = z_intensity_; break;
10121012
default: break;

src/openms/source/CONCEPT/Exception.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ namespace OpenMS
145145
GlobalExceptionHandler::getInstance().setMessage(what());
146146
}
147147

148-
InvalidSize::InvalidSize(const char* file, int line, const char* function, Size size) noexcept :
149-
BaseException(file, line, function, "InvalidSize", "the given size was not expected: " + String(size))
148+
InvalidSize::InvalidSize(const char* file, int line, const char* function, Size size, const std::string& message) noexcept :
149+
BaseException(file, line, function, "InvalidSize", "the given size was not expected: " + String(size) + " (" + message + ")")
150150
{
151151
GlobalExceptionHandler::getInstance().setMessage(what());
152152
}

src/openms/source/FEATUREFINDER/MassTraceDetection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ namespace OpenMS
120120
{
121121
if (fda[idx].size() != spec.size())
122122
{
123-
throw OpenMS::Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, spec.size());
123+
throw OpenMS::Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, spec.size(), "FloatDataArray size does not match spectrum size");
124124
}
125125
++valid_count;
126126
}

src/openms/source/FEATUREFINDER/MultiplexDeltaMassesGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ namespace OpenMS
356356
if (delta_masses_list_.empty())
357357
{
358358
// Even in the case of a singlet search, there should be one mass shift (zero mass shift) in the list.
359-
throw OpenMS::Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 0);
359+
throw OpenMS::Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 0, "delta_masses_list_ must not be empty");
360360
}
361361

362362
unsigned n = delta_masses_list_[0].getDeltaMasses().size(); // n=1 for singlets, n=2 for doublets, n=3 for triplets, n=4 for quadruplets

src/openms/source/FEATUREFINDER/MultiplexFiltering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ namespace OpenMS
483483
// Calculate Pearson and Spearman rank correlations
484484
if ((intensities_model.size() < isotopes_per_peptide_min_) || (intensities_data.size() < isotopes_per_peptide_min_))
485485
{
486-
throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 0);
486+
throw Exception::InvalidSize(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, 0, "intensity vectors too small for correlation calculation");
487487
}
488488
double correlation_Pearson = OpenMS::Math::pearsonCorrelationCoefficient(intensities_model.begin(), intensities_model.end(), intensities_data.begin(), intensities_data.end());
489489
double correlation_Spearman = OpenMS::Math::rankCorrelationCoefficient(intensities_model.begin(), intensities_model.end(), intensities_data.begin(), intensities_data.end());

0 commit comments

Comments
 (0)