Skip to content

Commit 7597cd3

Browse files
authored
Merge pull request #457 from sbmlteam/sk/log_converter_errors
Sk/log converter errors
2 parents 7ce3408 + c8948c1 commit 7597cd3

File tree

10 files changed

+382
-19
lines changed

10 files changed

+382
-19
lines changed

src/sbml/SBMLError.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,10 @@ typedef enum
767767
, LocalParameterShadowsId = 81121 /*!< Local parameters defined within a kinetic law shadow global object symbols. */
768768
, LibSBMLAdditionalCodesLowerBound = 90000 /*!< Lower boundary of libSBML-specific diagnostic codes. */
769769
, CannotConvertToL1V1 = 90001 /*!< Cannot convert to SBML Level 1 Version 1. */
770+
, DocumentOrModelIsNull = 90101 /*!< The SBMLDocument or Model pointer is null. */
771+
, ModelContainsNoRateRules = 90102 /*!< The model contains no rate rules. */
772+
, ModelAlreadyContainsReactions = 90103 /*!< The model already contains reactions. */
773+
, ModelContainsMultipleCompartments = 90104 /*!< The model contains multiple compartments. */
770774
, NoEventsInL1 = 91001 /*!< SBML Level 1 does not support events. */
771775
, NoFunctionDefinitionsInL1 = 91002 /*!< SBML Level 1 does not support function definitions. */
772776
, NoConstraintsInL1 = 91003 /*!< SBML Level 1 does not support constraints. */
@@ -1042,6 +1046,8 @@ typedef enum
10421046
, LIBSBML_CAT_STRICT_UNITS_CONSISTENCY
10431047
/*!< Category of errors that occur running the strict unit
10441048
* validator. */
1049+
, LIBSBML_CAT_RATE_RULE_CONVERSION
1050+
/*!< Category of warnings about rate rule conversions */
10451051

10461052
} SBMLErrorCategory_t;
10471053

src/sbml/SBMLErrorTable.h

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8062,6 +8062,108 @@ static const sbmlErrorTableEntry errorTable[] =
80628062
""}
80638063
},
80648064

8065+
/* --------------------------------------------------------------------------
8066+
* Rate rule conversion errors.
8067+
* ----------------------------------------------------------------------- */
8068+
//90101
8069+
{
8070+
DocumentOrModelIsNull,
8071+
"Document or model is null",
8072+
LIBSBML_CAT_RATE_RULE_CONVERSION,
8073+
LIBSBML_SEV_ERROR,
8074+
LIBSBML_SEV_ERROR,
8075+
LIBSBML_SEV_ERROR,
8076+
LIBSBML_SEV_ERROR,
8077+
LIBSBML_SEV_ERROR,
8078+
LIBSBML_SEV_ERROR,
8079+
LIBSBML_SEV_ERROR,
8080+
LIBSBML_SEV_ERROR,
8081+
LIBSBML_SEV_ERROR,
8082+
"There is no document or model to convert.",
8083+
{"",
8084+
"",
8085+
"",
8086+
"",
8087+
"",
8088+
"",
8089+
"",
8090+
""}
8091+
},
8092+
8093+
//90102
8094+
{
8095+
ModelContainsNoRateRules,
8096+
"Model contains no rate rules",
8097+
LIBSBML_CAT_RATE_RULE_CONVERSION,
8098+
LIBSBML_SEV_WARNING,
8099+
LIBSBML_SEV_WARNING,
8100+
LIBSBML_SEV_WARNING,
8101+
LIBSBML_SEV_WARNING,
8102+
LIBSBML_SEV_WARNING,
8103+
LIBSBML_SEV_WARNING,
8104+
LIBSBML_SEV_WARNING,
8105+
LIBSBML_SEV_WARNING,
8106+
LIBSBML_SEV_WARNING,
8107+
"The model contains no rate rules and so cannot be converted to reactions.",
8108+
{"",
8109+
"",
8110+
"",
8111+
"",
8112+
"",
8113+
"",
8114+
"",
8115+
""}
8116+
},
8117+
8118+
//90103S.NESSTALENT SLEEP
8119+
{
8120+
ModelAlreadyContainsReactions,
8121+
"Model already contains reactions",
8122+
LIBSBML_CAT_RATE_RULE_CONVERSION,
8123+
LIBSBML_SEV_ERROR,
8124+
LIBSBML_SEV_ERROR,
8125+
LIBSBML_SEV_ERROR,
8126+
LIBSBML_SEV_ERROR,
8127+
LIBSBML_SEV_ERROR,
8128+
LIBSBML_SEV_ERROR,
8129+
LIBSBML_SEV_ERROR,
8130+
LIBSBML_SEV_ERROR,
8131+
LIBSBML_SEV_ERROR,
8132+
"The model already contains reactions; rate rule conversiondoes not yet support converting a model with a mixture of reactions and rate rules.",
8133+
{"",
8134+
"",
8135+
"",
8136+
"",
8137+
"",
8138+
"",
8139+
"",
8140+
""}
8141+
},
8142+
8143+
//90104
8144+
{
8145+
ModelContainsMultipleCompartments,
8146+
"Model contains multiple compartments",
8147+
LIBSBML_CAT_RATE_RULE_CONVERSION,
8148+
LIBSBML_SEV_ERROR,
8149+
LIBSBML_SEV_ERROR,
8150+
LIBSBML_SEV_ERROR,
8151+
LIBSBML_SEV_ERROR,
8152+
LIBSBML_SEV_ERROR,
8153+
LIBSBML_SEV_ERROR,
8154+
LIBSBML_SEV_ERROR,
8155+
LIBSBML_SEV_ERROR,
8156+
LIBSBML_SEV_ERROR,
8157+
"The model contains multiple compartments; rate rule conversion does not yet support models with multiple compartments.",
8158+
{"",
8159+
"",
8160+
"",
8161+
"",
8162+
"",
8163+
"",
8164+
"",
8165+
""}
8166+
},
80658167
/* --------------------------------------------------------------------------
80668168
* L1 compatibility.
80678169
* ----------------------------------------------------------------------- */

src/sbml/conversion/SBMLRateRuleConverter.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -363,21 +363,25 @@ SBMLRateRuleConverter::isDocumentAppropriate(OperationReturnValues_t& returnValu
363363
// 1. document is null or model is null
364364
if (mDocument == NULL)
365365
{
366-
returnValue = LIBSBML_INVALID_OBJECT;
367-
return false;
366+
returnValue = LIBSBML_OPERATION_FAILED;
367+
return false;
368368
}
369369
Model* mModel = mDocument->getModel();
370370
if (mModel == NULL)
371371
{
372-
returnValue = LIBSBML_INVALID_OBJECT;
373-
return false;
372+
mDocument->getErrorLog()->logError(DocumentOrModelIsNull, mDocument->getLevel(),
373+
mDocument->getVersion(), "The source document or model is null.");
374+
returnValue = LIBSBML_OPERATION_FAILED;
375+
return false;
374376
}
375377

376378
// 2. there are no rate rules/already reactions/multiple compartments
377379
if (mModel->getNumRules() == 0)
378380
{
379-
returnValue = LIBSBML_OPERATION_SUCCESS;
380-
return false;
381+
mDocument->getErrorLog()->logError(ModelContainsNoRateRules, mDocument->getLevel(),
382+
mDocument->getVersion(), "There are no rate rules present.");
383+
returnValue = LIBSBML_OPERATION_SUCCESS;
384+
return true;
381385
}
382386
else
383387
{
@@ -393,27 +397,33 @@ SBMLRateRuleConverter::isDocumentAppropriate(OperationReturnValues_t& returnValu
393397
}
394398
if (!rateRule)
395399
{
396-
returnValue = LIBSBML_OPERATION_SUCCESS;
397-
return false;
400+
mDocument->getErrorLog()->logError(ModelContainsNoRateRules, mDocument->getLevel(),
401+
mDocument->getVersion(), "There are no rate rules present.");
402+
returnValue = LIBSBML_OPERATION_SUCCESS;
403+
return false;
398404
}
399405
}
400406

401407
if (mModel->getNumReactions() > 0)
402408
{
403-
returnValue = LIBSBML_OPERATION_SUCCESS;
404-
return false;
409+
mDocument->getErrorLog()->logError(ModelAlreadyContainsReactions, mDocument->getLevel(),
410+
mDocument->getVersion(), "There are already reactions present.");
411+
returnValue = LIBSBML_OPERATION_FAILED;
412+
return false;
405413
}
406414

407415
if (mModel->getNumCompartments() > 1)
408416
{
409-
returnValue = LIBSBML_OPERATION_SUCCESS;
410-
return false;
417+
mDocument->getErrorLog()->logError(ModelContainsMultipleCompartments, mDocument->getLevel(),
418+
mDocument->getVersion(), "There are multiple compartments.");
419+
returnValue = LIBSBML_OPERATION_FAILED;
420+
return false;
411421
}
412422

413423
// 3. the document is invalid
414424
if (checkDocumentValidity() == false)
415425
{
416-
returnValue = LIBSBML_CONV_INVALID_SRC_DOCUMENT;
426+
returnValue = LIBSBML_OPERATION_FAILED;
417427
return false;
418428
}
419429

src/sbml/conversion/test/TestRoundtripConverter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* <!--------------------------------------------------------------------------
77
* This file is part of libSBML. Please visit http://sbml.org for more
88
* information about SBML, and the latest version of libSBML.
9-
*
10-
* Copyright (C) 2013-2018 jointly by the following organizations:
9+
*
1110
* 1. California Institute of Technology, Pasadena, CA, USA
1211
* 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
1312
* 3. University of Heidelberg, Heidelberg, Germany

src/sbml/conversion/test/TestSBMLRateRuleConverter.cpp

Lines changed: 121 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ START_TEST(test_conversion_raterule_converter_invalid)
217217
SBMLDocument* doc = NULL;
218218
rule_rn_converter->setDocument(doc);
219219

220-
fail_unless(rule_rn_converter->convert() == LIBSBML_INVALID_OBJECT);
220+
fail_unless(rule_rn_converter->convert() == LIBSBML_OPERATION_FAILED);
221221

222222
// test NULL model
223223
doc = new SBMLDocument(3, 2);
224224
rule_rn_converter->setDocument(doc);
225225

226-
fail_unless(rule_rn_converter->convert() == LIBSBML_INVALID_OBJECT);
226+
fail_unless(rule_rn_converter->convert() == LIBSBML_OPERATION_FAILED);
227227

228228
// create model no rules
229229
Model* model = doc->createModel();
@@ -252,7 +252,7 @@ START_TEST(test_conversion_raterule_converter_invalid)
252252
// invalid document
253253
rule_rn_converter->setDocument(doc);
254254

255-
fail_unless(rule_rn_converter->convert() == LIBSBML_CONV_INVALID_SRC_DOCUMENT);
255+
fail_unless(rule_rn_converter->convert() == LIBSBML_OPERATION_FAILED);
256256

257257
delete doc;
258258
}
@@ -375,7 +375,7 @@ START_TEST(test_crash_converter)
375375

376376
// ensure that we dont crash on null document
377377
rule_rn_converter->setDocument((SBMLDocument*)NULL);
378-
fail_unless(rule_rn_converter->convert() == LIBSBML_INVALID_OBJECT);
378+
fail_unless(rule_rn_converter->convert() == LIBSBML_OPERATION_FAILED);
379379

380380
}
381381
END_TEST
@@ -1026,6 +1026,115 @@ START_TEST(test_rule_reaction_55)
10261026
}
10271027
END_TEST
10281028

1029+
START_TEST(test_converter_errors)
1030+
{
1031+
std::string raterule_file(TestDataDirectory);
1032+
raterule_file += "rn_rr_fail_90101.xml";
1033+
1034+
SBMLDocument* d = readSBMLFromFile(raterule_file.c_str());
1035+
1036+
rule_rn_props.addOption("useStoichiometryFromMath", true);
1037+
rule_rn_converter->setProperties(&rule_rn_props);
1038+
1039+
1040+
rule_rn_converter->setDocument(d);
1041+
int ret = rule_rn_converter->convert();
1042+
fail_unless(ret == LIBSBML_OPERATION_FAILED);
1043+
fail_unless(d->getNumErrors() == 2);
1044+
// we'll also contain 20201 - model must contain a document
1045+
fail_unless(d->getError(1)->getErrorId() == 90101);
1046+
fail_unless(d->getError(1)->getCategory() == LIBSBML_CAT_RATE_RULE_CONVERSION);
1047+
1048+
delete d;
1049+
}
1050+
END_TEST
1051+
1052+
START_TEST(test_converter_errors_1)
1053+
{
1054+
std::string raterule_file(TestDataDirectory);
1055+
raterule_file += "rn_rr_fail_90102_1.xml";
1056+
1057+
SBMLDocument* d = readSBMLFromFile(raterule_file.c_str());
1058+
1059+
rule_rn_props.addOption("useStoichiometryFromMath", true);
1060+
rule_rn_converter->setProperties(&rule_rn_props);
1061+
1062+
1063+
rule_rn_converter->setDocument(d);
1064+
int ret = rule_rn_converter->convert();
1065+
fail_unless(ret == LIBSBML_OPERATION_SUCCESS);
1066+
fail_unless(d->getNumErrors() == 1);
1067+
fail_unless(d->getError(0)->getErrorId() == 90102);
1068+
fail_unless(d->getError(0)->getCategory() == LIBSBML_CAT_RATE_RULE_CONVERSION);
1069+
1070+
delete d;
1071+
}
1072+
END_TEST
1073+
1074+
START_TEST(test_converter_errors_2)
1075+
{
1076+
std::string raterule_file(TestDataDirectory);
1077+
raterule_file += "rn_rr_fail_90102_2.xml";
1078+
1079+
SBMLDocument* d = readSBMLFromFile(raterule_file.c_str());
1080+
1081+
rule_rn_props.addOption("useStoichiometryFromMath", true);
1082+
rule_rn_converter->setProperties(&rule_rn_props);
1083+
1084+
1085+
rule_rn_converter->setDocument(d);
1086+
int ret = rule_rn_converter->convert();
1087+
fail_unless(ret == LIBSBML_OPERATION_SUCCESS);
1088+
fail_unless(d->getNumErrors() == 1);
1089+
fail_unless(d->getError(0)->getErrorId() == 90102);
1090+
fail_unless(d->getError(0)->getCategory() == LIBSBML_CAT_RATE_RULE_CONVERSION);
1091+
1092+
delete d;
1093+
}
1094+
END_TEST
1095+
START_TEST(test_converter_errors_3)
1096+
{
1097+
std::string raterule_file(TestDataDirectory);
1098+
raterule_file += "rn_rr_fail_90103.xml";
1099+
1100+
SBMLDocument* d = readSBMLFromFile(raterule_file.c_str());
1101+
1102+
rule_rn_props.addOption("useStoichiometryFromMath", true);
1103+
rule_rn_converter->setProperties(&rule_rn_props);
1104+
1105+
1106+
rule_rn_converter->setDocument(d);
1107+
int ret = rule_rn_converter->convert();
1108+
fail_unless(ret == LIBSBML_OPERATION_FAILED);
1109+
fail_unless(d->getNumErrors() == 1);
1110+
fail_unless(d->getError(0)->getErrorId() == 90103);
1111+
fail_unless(d->getError(0)->getCategory() == LIBSBML_CAT_RATE_RULE_CONVERSION);
1112+
1113+
delete d;
1114+
}
1115+
END_TEST
1116+
START_TEST(test_converter_errors_4)
1117+
{
1118+
std::string raterule_file(TestDataDirectory);
1119+
raterule_file += "rn_rr_fail_90104.xml";
1120+
1121+
SBMLDocument* d = readSBMLFromFile(raterule_file.c_str());
1122+
1123+
rule_rn_props.addOption("useStoichiometryFromMath", true);
1124+
rule_rn_converter->setProperties(&rule_rn_props);
1125+
1126+
1127+
rule_rn_converter->setDocument(d);
1128+
int ret = rule_rn_converter->convert();
1129+
fail_unless(ret == LIBSBML_OPERATION_FAILED);
1130+
fail_unless(d->getNumErrors() == 1);
1131+
fail_unless(d->getError(0)->getErrorId() == 90104);
1132+
fail_unless(d->getError(0)->getCategory() == LIBSBML_CAT_RATE_RULE_CONVERSION);
1133+
1134+
delete d;
1135+
}
1136+
END_TEST
1137+
10291138
Suite *
10301139
create_suite_TestSBMLRateRuleConverter (void)
10311140
{
@@ -1070,6 +1179,14 @@ Suite *suite = suite_create("SBMLRateRuleConverter");
10701179
//tcase_add_test(tcase, test_rule_reaction_53);
10711180
//tcase_add_test(tcase, test_rule_reaction_54);
10721181
//tcase_add_test(tcase, test_rule_reaction_55);
1182+
tcase_add_test(tcase, test_converter_errors);
1183+
tcase_add_test(tcase, test_converter_errors_1);
1184+
tcase_add_test(tcase, test_converter_errors_2);
1185+
tcase_add_test(tcase, test_converter_errors_3);
1186+
tcase_add_test(tcase, test_converter_errors_4);
1187+
1188+
1189+
10731190
}
10741191
suite_add_tcase(suite, tcase);
10751192

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<sbml xmlns="http://www.sbml.org/sbml/level3/version1/core" level="3" version="1">
3+
</sbml>

0 commit comments

Comments
 (0)