fix(codegen): check fstream status and report in case of failure (#462)

This commit is contained in:
Karl Ljungkvist
2024-10-31 12:48:19 +01:00
committed by GitHub
parent c55907069b
commit 84130b1406
2 changed files with 10 additions and 3 deletions

View File

@@ -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;

View File

@@ -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)
@@ -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;