Skip to content

Commit e854479

Browse files
author
Marcel Hecko
committed
Improve DSM diagram loading error diagnostics (#286)
When a .dsm file fails to load, the error messages were too terse to diagnose the root cause. This adds: - errno details on file open failures (e.g. "No such file or directory") - A hint when the file exists with a .dsm extension appended, suggesting the user fix their #include directive - Context showing which #include directive in which parent file caused a recursive load failure - The configured diag_path value in the top-level load error so users can verify their configuration
1 parent 93c7c17 commit e854479

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

apps/dsm/DSM.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,10 @@ bool DSMFactory::loadDiags(AmConfigReader& cfg, DSMStateDiagramCollection* m_dia
368368
for (vector<string>::iterator it=
369369
diags_names.begin(); it != diags_names.end(); it++) {
370370
if (!m_diags->loadFile(DiagPath+*it+".dsm", *it, DiagPath, ModPath, DebugDSM, CheckDSM)) {
371-
ERROR("loading %s from %s\n",
371+
ERROR("loading diagram '%s' from '%s' failed\n",
372372
it->c_str(), (DiagPath+*it+".dsm").c_str());
373+
ERROR(" Check that diag_path='%s' is correct and '%s' is readable by the SEMS process\n",
374+
DiagPath.c_str(), (DiagPath+*it+".dsm").c_str());
373375
return false;
374376
}
375377
}

apps/dsm/DSMStateDiagramCollection.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <fstream>
3131
using std::ifstream;
3232

33+
#include <cerrno>
3334
#include <dirent.h>
3435

3536
DSMStateDiagramCollection::DSMStateDiagramCollection() {
@@ -44,8 +45,16 @@ bool DSMStateDiagramCollection::readFile(const string& filename, const string& n
4445

4546
ifstream ifs(filename.c_str());
4647
if (!ifs.good()) {
47-
ERROR("loading state diagram '%s'\n",
48-
filename.c_str());
48+
ERROR("loading state diagram '%s': cannot open file (%s)\n",
49+
filename.c_str(), strerror(errno));
50+
51+
// Check if the user forgot the .dsm extension (common #include mistake)
52+
string with_ext = filename + ".dsm";
53+
ifstream test_ifs(with_ext.c_str());
54+
if (test_ifs.good()) {
55+
ERROR(" Hint: '%s' exists - did you mean to use '%s' in your #include directive?\n",
56+
with_ext.c_str(), with_ext.c_str());
57+
}
4958
return false;
5059
}
5160

@@ -92,6 +101,8 @@ bool DSMStateDiagramCollection::readFile(const string& filename, const string& n
92101
if (name.rfind(".dsm") != (name.size() - 4)) continue;
93102
include_dir_name = include_name + "/" + name;
94103
if (!readFile(include_dir_name, name, current_load_path, s)) {
104+
ERROR(" while processing '#include %s' (directory entry '%s') in '%s'\n",
105+
include_name.c_str(), include_dir_name.c_str(), filename.c_str());
95106
(void)closedir(dp);
96107
return false;
97108
}
@@ -102,8 +113,11 @@ bool DSMStateDiagramCollection::readFile(const string& filename, const string& n
102113
return false;
103114
}
104115
} else {
105-
if (!readFile(include_name, name, current_load_path, s))
116+
if (!readFile(include_name, name, current_load_path, s)) {
117+
ERROR(" while processing '#include %s' in '%s'\n",
118+
include_name.c_str(), filename.c_str());
106119
return false;
120+
}
107121
}
108122
continue;
109123
}

0 commit comments

Comments
 (0)