Skip to content

Commit 0a29d8c

Browse files
authored
Improved warning/error messages.
2 parents b763d30 + 913a4a9 commit 0a29d8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+436
-327
lines changed

src/api/libopencor/issue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class LIBOPENCOR_EXPORT Issue
9393

9494
Impl *mPimpl; /**< The private implementation, @private. */
9595

96-
explicit Issue(Type pType, const std::string &pDescription); /**< Constructor, @private. */
96+
explicit Issue(Type pType, const std::string &pDescription, const std::string &pContext); /**< Constructor, @private. */
9797
};
9898

9999
} // namespace libOpenCOR

src/file/file.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,21 @@ void File::Impl::checkType(const FilePtr &pOwner, bool pResetType)
9595
if (mCellmlFile != nullptr) {
9696
mType = Type::CELLML_FILE;
9797

98-
addIssues(mCellmlFile);
98+
addIssues(mCellmlFile, "CellML file");
9999
} else {
100100
mSedmlFile = SedmlFile::create(pOwner);
101101

102102
if (mSedmlFile != nullptr) {
103103
mType = Type::SEDML_FILE;
104104

105-
addIssues(mSedmlFile);
105+
addIssues(mSedmlFile, "SED-ML file");
106106
} else {
107107
mCombineArchive = CombineArchive::create(pOwner);
108108

109109
if (mCombineArchive != nullptr) {
110110
mType = Type::COMBINE_ARCHIVE;
111111

112-
addIssues(mCombineArchive);
112+
addIssues(mCombineArchive, "COMBINE archive");
113113
} else {
114114
addError("The file is not a CellML file, a SED-ML file, or a COMBINE archive.");
115115
}

src/logger/issue.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ limitations under the License.
1818

1919
namespace libOpenCOR {
2020

21-
Issue::Impl::Impl(Type pType, const std::string &pDescription)
21+
Issue::Impl::Impl(Type pType, const std::string &pDescription, const std::string &pContext)
2222
: mType(pType)
2323
, mDescription(pDescription)
24+
, mContext(pContext)
2425
{
2526
}
2627

@@ -36,11 +37,27 @@ std::string Issue::Impl::typeAsString() const
3637

3738
std::string Issue::Impl::description() const
3839
{
40+
// Check whether we have some context to add to the description.
41+
42+
if (!mContext.empty()) {
43+
auto description {mDescription};
44+
45+
#ifndef CODE_COVERAGE_ENABLED
46+
if (std::isupper(description[0]) != 0) {
47+
#endif
48+
description[0] = static_cast<char>(std::tolower(description[0]));
49+
#ifndef CODE_COVERAGE_ENABLED
50+
}
51+
#endif
52+
53+
return mContext + ": " + description;
54+
}
55+
3956
return mDescription;
4057
}
4158

42-
Issue::Issue(Type pType, const std::string &pDescription)
43-
: mPimpl(new Impl {pType, pDescription})
59+
Issue::Issue(Type pType, const std::string &pDescription, const std::string &pContext)
60+
: mPimpl(new Impl {pType, pDescription, pContext})
4461
{
4562
}
4663

src/logger/issue_p.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ class Issue::Impl
2525
public:
2626
Type mType;
2727
std::string mDescription;
28+
std::string mContext;
2829

29-
explicit Impl(Type pType, const std::string &pDescription);
30+
explicit Impl(Type pType, const std::string &pDescription, const std::string &pContext);
3031

3132
Type type() const;
3233
std::string typeAsString() const;

src/logger/logger.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
#include "issue_p.h"
1718
#include "logger_p.h"
1819

1920
namespace libOpenCOR {
@@ -90,27 +91,28 @@ IssuePtr Logger::Impl::warning(size_t pIndex) const
9091
return mWarnings[pIndex];
9192
}
9293

93-
void Logger::Impl::addIssues(const LoggerPtr &pLogger)
94+
void Logger::Impl::addIssues(const LoggerPtr &pLogger, const std::string &pContext)
9495
{
9596
for (const auto &issue : pLogger->issues()) {
96-
addIssue(issue->type(), issue->description());
97+
addIssue(issue->type(), issue->mPimpl->mDescription,
98+
issue->mPimpl->mContext.empty() ? pContext : pContext + " | " + issue->mPimpl->mContext);
9799
}
98100
}
99101

100-
void Logger::Impl::addIssues(const libcellml::LoggerPtr &pLogger)
102+
void Logger::Impl::addIssues(const libcellml::LoggerPtr &pLogger, const std::string &pContext)
101103
{
102104
for (size_t i {0}; i < pLogger->issueCount(); ++i) {
103105
auto issue {pLogger->issue(i)};
104106

105107
addIssue((issue->level() == libcellml::Issue::Level::ERROR) ? Issue::Type::ERROR :
106108
Issue::Type::WARNING,
107-
issue->description());
109+
issue->description(), pContext);
108110
}
109111
}
110112

111-
void Logger::Impl::addIssue(Issue::Type pType, const std::string &pDescription)
113+
void Logger::Impl::addIssue(Issue::Type pType, const std::string &pDescription, const std::string &pContext)
112114
{
113-
auto issue {IssuePtr {new Issue {pType, pDescription}}};
115+
auto issue {IssuePtr {new Issue {pType, pDescription, pContext}}};
114116
mIssues.push_back(issue);
115117

116118
if (pType == Issue::Type::ERROR) {

src/logger/logger_p.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ class Logger::Impl
4949
IssuePtrs warnings() const;
5050
IssuePtr warning(size_t pIndex) const;
5151

52-
void addIssues(const LoggerPtr &pLogger);
53-
void addIssues(const libcellml::LoggerPtr &pLogger);
52+
void addIssues(const LoggerPtr &pLogger, const std::string &pContext);
53+
void addIssues(const libcellml::LoggerPtr &pLogger, const std::string &pContext);
5454

55-
void addIssue(Issue::Type pType, const std::string &pDescription);
55+
void addIssue(Issue::Type pType, const std::string &pDescription, const std::string &pContext = "");
5656

5757
void addError(const std::string &pDescription);
5858
void addWarning(const std::string &pDescription);

src/sed/seddocument.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void SedDocument::Impl::initialiseFromSedmlFile(const SedDocumentPtr &pOwner, co
9191

9292
sedmlFile->populateDocument(pOwner);
9393

94-
addIssues(sedmlFile);
94+
addIssues(sedmlFile, "SED-ML file");
9595
}
9696

9797
void SedDocument::Impl::initialiseFromCombineArchive(const SedDocumentPtr &pOwner, const FilePtr &pFile)

src/sed/sedinstance.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ SedInstance::Impl::Impl(const SedDocumentPtr &pDocument)
4848
// Make sure that the task is valid.
4949

5050
if (!taskPimpl->isValid()) {
51-
addIssues(task);
51+
addIssues(task, "Task");
5252

5353
tasksValid = false;
5454
}
@@ -63,7 +63,7 @@ SedInstance::Impl::Impl(const SedDocumentPtr &pDocument)
6363
mTasks.push_back(taskInstance);
6464

6565
if (taskInstance->hasIssues()) {
66-
addIssues(taskInstance);
66+
addIssues(taskInstance, "Task instance");
6767
}
6868
}
6969
}
@@ -93,7 +93,7 @@ double SedInstance::Impl::run()
9393
res += task->pimpl()->run();
9494

9595
if (task->hasIssues()) {
96-
addIssues(task);
96+
addIssues(task, "Task");
9797

9898
// Reset the issues of the task so that they are not reported again should the instance be run again.
9999

src/sed/sedinstancetask.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ SedInstanceTask::Impl::Impl(const SedAbstractTaskPtr &pTask)
7373

7474
#ifndef CODE_COVERAGE_ENABLED
7575
if (mRuntime->hasErrors()) {
76-
addIssues(mRuntime);
76+
addIssues(mRuntime, "Runtime");
7777

7878
return;
7979
}
@@ -141,7 +141,7 @@ void SedInstanceTask::Impl::applyChanges()
141141

142142
changeAttribute->pimpl()->apply(mOwner.lock(), mAnalyserModel);
143143

144-
addIssues(changeAttribute);
144+
addIssues(changeAttribute, "Change attribute");
145145
}
146146
}
147147

@@ -194,7 +194,7 @@ void SedInstanceTask::Impl::initialise()
194194
// Make sure that the NLA solver, should it have been used, didn't report any issues.
195195

196196
if ((mNlaSolver != nullptr) && mNlaSolver->hasIssues()) {
197-
addIssues(mNlaSolver);
197+
addIssues(mNlaSolver, mNlaSolver->name());
198198

199199
return;
200200
}
@@ -205,7 +205,7 @@ void SedInstanceTask::Impl::initialise()
205205
if (!mOdeSolver->pimpl()->initialise(mVoi, mAnalyserModel->stateCount(), mStates, mRates,
206206
mConstants, mComputedConstants, mAlgebraic,
207207
mRuntime)) {
208-
addIssues(mOdeSolver);
208+
addIssues(mOdeSolver, mOdeSolver->name());
209209

210210
return;
211211
}
@@ -264,7 +264,7 @@ double SedInstanceTask::Impl::run()
264264

265265
while (!fuzzyCompare(mVoi, voiEnd)) {
266266
if (!mOdeSolver->pimpl()->solve(mVoi, std::min(voiStart + static_cast<double>(++voiCounter) * voiInterval, voiEnd))) {
267-
addIssues(mOdeSolver);
267+
addIssues(mOdeSolver, mOdeSolver->name());
268268

269269
return 0.0;
270270
}
@@ -283,7 +283,7 @@ double SedInstanceTask::Impl::run()
283283

284284
#ifndef CODE_COVERAGE_ENABLED
285285
if ((mNlaSolver != nullptr) && mNlaSolver->hasIssues()) {
286-
addIssues(mNlaSolver);
286+
addIssues(mNlaSolver, mNlaSolver->name());
287287

288288
return 0.0;
289289
}

src/sed/sedmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool SedModel::Impl::isValid()
6565
break;
6666
}
6767

68-
addIssues(mFile->pimpl()->mCellmlFile);
68+
addIssues(mFile->pimpl()->mCellmlFile, "CellML");
6969

7070
return !hasErrors();
7171
}

0 commit comments

Comments
 (0)