diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-04-22 18:32:46 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-04-22 18:32:46 +0200 |
commit | 16143f324c030579d447679d5741b63796a4ac9b (patch) | |
tree | 887fa63758205ab24fae5395ac2e4244a2e51067 /bbot/utility.txx | |
parent | 1fef20e94bd9960da1b2ea0b2a41b94a79f8abc5 (diff) |
Make HTTP soft error handling more robust
Diffstat (limited to 'bbot/utility.txx')
-rw-r--r-- | bbot/utility.txx | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/bbot/utility.txx b/bbot/utility.txx index 4ee4c6f..231bd8f 100644 --- a/bbot/utility.txx +++ b/bbot/utility.txx @@ -157,7 +157,7 @@ namespace bbot fail << what << " manifest file " << f << " does not exist"; ifdstream ifs (f); - return parse_manifest<T> (ifs, f.string (), what, ignore_unknown); + return parse_manifest<T> (ifs, f.string (), what, true, ignore_unknown); } catch (const system_error& e) // EACCES, etc. { @@ -171,6 +171,7 @@ namespace bbot parse_manifest (istream& is, const string& name, const char* what, + bool hard, bool ignore_unknown) { using namespace butl; @@ -182,15 +183,19 @@ namespace bbot } catch (const manifest_parsing& e) { - fail << "invalid " << what << " manifest: " - << name << ':' << e.line << ':' << e.column << ": " << e.description - << endf; + diag_record dr; if (hard) dr << fail; else dr << error; + + dr << "invalid " << what << " manifest: " + << name << ':' << e.line << ':' << e.column << ": " << e.description; } catch (const io_error& e) { - fail << "unable to read " << what << " manifest " << name << ": " << e - << endf; + diag_record dr; if (hard) dr << fail; else dr << error; + + dr << "unable to read " << what << " manifest " << name << ": " << e; } + + throw failed (); } template <typename T> @@ -205,7 +210,7 @@ namespace bbot ofdstream ofs (f, ios::binary); auto_rmfile arm (f); // Try to remove on failure ignoring errors. - serialize_manifest (m, ofs, f.string (), what); + serialize_manifest (m, ofs, f.string (), what, true); ofs.close (); arm.cancel (); @@ -221,7 +226,8 @@ namespace bbot serialize_manifest (const T& m, ostream& os, const string& name, - const char* what) + const char* what, + bool hard) { using namespace butl; @@ -229,14 +235,21 @@ namespace bbot { manifest_serializer s (os, name); m.serialize (s); + return; } catch (const manifest_serialization& e) { - fail << "invalid " << what << " manifest: " << e.description; + diag_record dr; if (hard) dr << fail; else dr << error; + + dr << "invalid " << what << " manifest: " << e.description; } catch (const io_error& e) { + diag_record dr; if (hard) dr << fail; else dr << error; + fail << "unable to write " << what << " manifest " << name << ": " << e; } + + throw failed (); } } |