Skip to content

Commit

Permalink
[webcanv] handle failures from canv_batch.htm
Browse files Browse the repository at this point in the history
If failure happens during image production, report it
and try to create other images
  • Loading branch information
linev committed Nov 26, 2024
1 parent e8a7784 commit 976ba41
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions gui/webdisplay/src/RWebDisplayHandle.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,6 @@ bool RWebDisplayHandle::ProduceImages(const std::vector<std::string> &fnames, co
// chrome creates dummy html file with mostly no content
// problem running chrome from /tmp directory, lets try work from home directory

printf("Handle chrome workaround\n");
chrome_tmp_workaround = true;
goto try_again;
}
Expand All @@ -1315,29 +1314,34 @@ bool RWebDisplayHandle::ProduceImages(const std::vector<std::string> &fnames, co
p = p2 + 6;
std::ofstream ofs(fnames[n]);
if ((p1 != std::string::npos) && (p2 != std::string::npos) && (p1 < p2)) {
ofs << dumpcont.substr(p1, p2-p1+6);
::Info("ProduceImages", "SVG file %s size %d bytes has been created", fnames[n].c_str(), (int) (p2-p1+6));
if (p2 - p1 > 10) {
ofs << dumpcont.substr(p1, p2 - p1 + 6);
::Info("ProduceImages", "SVG file %s size %d bytes has been created", fnames[n].c_str(), (int) (p2 - p1 + 6));
} else {
::Error("ProduceImages", "Failure producing %s", fnames[n].c_str());
}
} else {
R__LOG_ERROR(WebGUILog()) << "Fail to extract SVG from HTML dump " << dump_name;
ofs << "Failure!!!\n" << dumpcont;
::Error("ProduceImages", "Fail to extract %s from HTML dump", fnames[n].c_str());
return false;
}
} else {
auto p1 = dumpcont.find(";base64,", p);
auto p0 = dumpcont.find("<img src=", p);
auto p1 = dumpcont.find(";base64,", p0 + 8);
auto p2 = dumpcont.find("></div>", p1 + 4);
p = p2 + 5;

if ((p1 != std::string::npos) && (p2 != std::string::npos) && (p1 < p2)) {
if ((p0 != std::string::npos) && (p1 != std::string::npos) && (p2 != std::string::npos) && (p1 < p2)) {
auto base64 = dumpcont.substr(p1+8, p2-p1-9);
auto binary = TBase64::Decode(base64.c_str());

std::ofstream ofs(fnames[n], std::ios::binary);
ofs.write(binary.Data(), binary.Length());

::Info("ProduceImages", "Image file %s size %d bytes has been created", fnames[n].c_str(), (int) binary.Length());
if ((base64 == "failure") || (base64.length() < 10)) {
::Error("ProduceImages", "Failure producing %s", fnames[n].c_str());
} else {
auto binary = TBase64::Decode(base64.c_str());
std::ofstream ofs(fnames[n], std::ios::binary);
ofs.write(binary.Data(), binary.Length());
::Info("ProduceImages", "Image file %s size %d bytes has been created", fnames[n].c_str(), (int) binary.Length());
}
} else {
R__LOG_ERROR(WebGUILog()) << "Fail to extract image from dump HTML code " << dump_name;

::Error("ProduceImages", "Fail to extract %s from HTML dump", fnames[n].c_str());
return false;
}
}
Expand Down

0 comments on commit 976ba41

Please sign in to comment.