Skip to content

Commit 56d57bd

Browse files
author
Felix Faber
committed
Proper error reporting instead of "exit(-1)" call
1 parent 451532c commit 56d57bd

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

lib/importproject.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,13 @@ bool ImportProject::importVcxproj(const std::string& filename, std::map<std::str
909909
printError("Could not simplify path to referenced shared items project");
910910
exit(-1);
911911
}
912-
sharedItemsProjects.emplace_back(importVcxitems(pathToSharedItemsFile, fileFilters, cache));
912+
SharedItemsProject toAdd = importVcxitems(pathToSharedItemsFile, fileFilters, cache);
913+
if (!toAdd.successFull)
914+
{
915+
printError("Could not load shared items project \"" + pathToSharedItemsFile + "\" from original path \"" + std::string(projectAttribute) + "\".");
916+
return false;
917+
}
918+
sharedItemsProjects.emplace_back(toAdd);
913919
}
914920
}
915921
}
@@ -1015,12 +1021,12 @@ ImportProject::SharedItemsProject ImportProject::importVcxitems(const std::strin
10151021
const tinyxml2::XMLError error = doc.LoadFile(filename.c_str());
10161022
if (error != tinyxml2::XML_SUCCESS) {
10171023
printError(std::string("Visual Studio project file is not a valid XML - ") + tinyxml2::XMLDocument::ErrorIDToName(error));
1018-
exit(-1);
1024+
return result;
10191025
}
10201026
const tinyxml2::XMLElement* const rootnode = doc.FirstChildElement();
10211027
if (rootnode == nullptr) {
10221028
printError("Visual Studio project file has no XML root node");
1023-
exit(-1);
1029+
return result;
10241030
}
10251031
for (const tinyxml2::XMLElement* node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
10261032
if (std::strcmp(node->Name(), "ItemGroup") == 0) {
@@ -1037,7 +1043,7 @@ ImportProject::SharedItemsProject ImportProject::importVcxitems(const std::strin
10371043
result.sourceFiles.emplace_back(file);
10381044
} else {
10391045
printError("Could not find shared items source file");
1040-
exit(-1);
1046+
return result;
10411047
}
10421048
}
10431049
}
@@ -1053,6 +1059,7 @@ ImportProject::SharedItemsProject ImportProject::importVcxitems(const std::strin
10531059
}
10541060
}
10551061

1062+
result.successFull = true;
10561063
cache.emplace_back(result);
10571064
return result;
10581065
}

lib/importproject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class CPPCHECKLIB WARN_UNUSED ImportProject {
102102

103103
private:
104104
struct SharedItemsProject {
105+
bool successFull;
105106
std::string pathToProjectFile;
106107
std::vector<std::string> includePaths;
107108
std::vector<std::string> sourceFiles;

0 commit comments

Comments
 (0)