Skip to content

Commit

Permalink
fix(codegen): check fstream status and report in case of failure (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalj authored Oct 31, 2024
1 parent c559070 commit 84130b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tools/xml2cpp-codegen/BaseGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int BaseGenerator::transformXmlToFile(const Document& doc, const char* filename)
int BaseGenerator::writeToFile(const char* filename, const std::string& data) const
{
std::ofstream file(filename);
if (file.bad())
if (file.fail())
{
std::cerr << "Unable to write file " << filename << endl;
return 1;
Expand Down
11 changes: 9 additions & 2 deletions tools/xml2cpp-codegen/xml2cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ int main(int argc, char **argv)
std::cerr << "Generating proxy header " << proxy << endl;
}
ProxyGenerator pg;
pg.transformXmlToFile(doc, proxy);
if(pg.transformXmlToFile(doc, proxy)) {
std::cerr << "Failed to generate proxy header" << endl;
return 1;
}
}

if (adaptor)
Expand All @@ -196,7 +199,11 @@ int main(int argc, char **argv)
std::cerr << "Generating adaptor header " << adaptor << endl;
}
AdaptorGenerator ag;
ag.transformXmlToFile(doc, adaptor);
if(ag.transformXmlToFile(doc, adaptor)) {
std::cerr << "Failed to generate adaptor header" << endl;
return 1;
}

}

return 0;
Expand Down

0 comments on commit 84130b1

Please sign in to comment.