aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bbot/diagnostics.hxx13
-rw-r--r--bbot/machine.cxx10
-rw-r--r--bbot/utility.txx68
3 files changed, 35 insertions, 56 deletions
diff --git a/bbot/diagnostics.hxx b/bbot/diagnostics.hxx
index bfeeb2a..36a3cf2 100644
--- a/bbot/diagnostics.hxx
+++ b/bbot/diagnostics.hxx
@@ -129,6 +129,19 @@ namespace bbot
r.flush ();
throw failed ();
}) {}
+
+ // If hard is false, then we fail as an error (but still throw).
+ //
+ simple_prologue
+ operator() (bool hard = true) const
+ {
+ if (hard)
+ return simple_prologue (indent_, epilogue_, type_, name_);
+
+ simple_prologue r (error ());
+ r.epilogue = epilogue_;
+ return r;
+ }
};
using fail_mark = butl::diag_mark<fail_mark_base>;
diff --git a/bbot/machine.cxx b/bbot/machine.cxx
index 2f1e56b..8bc6359 100644
--- a/bbot/machine.cxx
+++ b/bbot/machine.cxx
@@ -383,11 +383,8 @@ namespace bbot
}
catch (const process_error& e)
{
- diag_record dr; if (fh) dr << fail; else dr << error;
- dr << "unable to execute " << kvm << ": " << e;
+ fail (fh) << "unable to execute " << kvm << ": " << e << endf;
}
-
- throw failed ();
}
void kvm_machine::
@@ -453,11 +450,8 @@ namespace bbot
}
catch (const system_error& e)
{
- diag_record dr; if (fh) dr << fail; else dr << error;
- dr << "unable to communicate with qemu monitor: " << e;
+ fail (fh) << "unable to communicate with qemu monitor: " << e;
}
-
- throw failed ();
}
unique_ptr<machine>
diff --git a/bbot/utility.txx b/bbot/utility.txx
index 31f9cdf..0eb5d75 100644
--- a/bbot/utility.txx
+++ b/bbot/utility.txx
@@ -52,35 +52,24 @@ namespace bbot
const process_exit& e (*pr.exit);
- if (e.normal ())
- return e.code ();
+ if (!e.normal ())
+ fail (fh) << "process " << p << " terminated abnormally: "
+ << e.description () << (e.core () ? " (core dumped)" : "");
- diag_record dr; if (fh) dr << fail; else dr << error;
- dr << "process " << p << " terminated abnormally: "
- << e.description () << (e.core () ? " (core dumped)" : "");
+ return e.code ();
}
catch (const process_error& e)
{
- diag_record dr; if (fh) dr << fail; else dr << error;
- dr << "unable to execute " << p << ": " << e;
+ fail (fh) << "unable to execute " << p << ": " << e << endf;
}
-
- throw failed ();
}
template <typename P>
inline void
run_io_finish (tracer& t, process& pr, const P& p, bool fh)
{
- if (run_io_finish_exit (t, pr, p, fh) == 0)
- return;
-
- {
- diag_record dr; if (fh) dr << fail; else dr << error;
- dr << "process " << p << " terminated with non-zero exit code";
- }
-
- throw failed ();
+ if (run_io_finish_exit (t, pr, p, fh) != 0)
+ fail (fh) << "process " << p << " terminated with non-zero exit code";
}
template <typename I, typename O, typename E, typename P, typename... A>
@@ -164,24 +153,17 @@ namespace bbot
if (f.string () == "-")
return parse_manifest<T> (std::cin, "stdin", what, fh, iu);
- if (file_exists (f))
- {
- ifdstream ifs (f);
- return parse_manifest<T> (ifs, f.string (), what, fh, iu);
- }
+ if (!file_exists (f))
+ fail (fh) << what << " manifest file " << f << " does not exist";
- diag_record dr; if (fh) dr << fail; else dr << error;
-
- dr << what << " manifest file " << f << " does not exist";
+ ifdstream ifs (f);
+ return parse_manifest<T> (ifs, f.string (), what, fh, iu);
}
catch (const system_error& e) // EACCES, etc.
{
- diag_record dr; if (fh) dr << fail; else dr << error;
-
- dr << "unable to access " << what << " manifest " << f << ": " << e;
+ fail (fh) << "unable to access " << what << " manifest " << f << ": "
+ << e << endf;
}
-
- throw failed ();
}
template <typename T>
@@ -201,19 +183,14 @@ namespace bbot
}
catch (const manifest_parsing& e)
{
- diag_record dr; if (fh) dr << fail; else dr << error;
-
- dr << "invalid " << what << " manifest: "
- << name << ':' << e.line << ':' << e.column << ": " << e.description;
+ fail (fh) << "invalid " << what << " manifest: " << name << ':'
+ << e.line << ':' << e.column << ": " << e.description << endf;
}
catch (const io_error& e)
{
- diag_record dr; if (fh) dr << fail; else dr << error;
-
- dr << "unable to read " << what << " manifest " << name << ": " << e;
+ fail (fh) << "unable to read " << what << " manifest " << name << ": "
+ << e << endf;
}
-
- throw failed ();
}
template <typename T>
@@ -257,17 +234,12 @@ namespace bbot
}
catch (const manifest_serialization& e)
{
- diag_record dr; if (fh) dr << fail; else dr << error;
-
- dr << "invalid " << what << " manifest: " << e.description;
+ fail (fh) << "invalid " << what << " manifest: " << e.description;
}
catch (const io_error& e)
{
- diag_record dr; if (fh) dr << fail; else dr << error;
-
- fail << "unable to write " << what << " manifest " << name << ": " << e;
+ fail (fh) << "unable to write " << what << " manifest " << name
+ << ": " << e;
}
-
- throw failed ();
}
}