From 32f153664e7b6cadfb518b83e12b9768a150d709 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 9 Dec 2020 15:10:56 +0300 Subject: Prefix pseudo-builtin diagnostincs messages with their names --- libbuild2/script/run.cxx | 16 ++++++++-------- libbuild2/script/timeout.cxx | 7 +++++-- libbuild2/script/timeout.hxx | 6 ++++-- libbuild2/script/timeout.ixx | 7 +++++-- 4 files changed, 22 insertions(+), 14 deletions(-) (limited to 'libbuild2/script') diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx index 90ddc4d..b1bc888 100644 --- a/libbuild2/script/run.cxx +++ b/libbuild2/script/run.cxx @@ -782,12 +782,12 @@ namespace build2 timeout_options ops (scan); if (!scan.more ()) - fail (ll) << "missing timeout"; + fail (ll) << "timeout: missing timeout"; string a (scan.next ()); if (scan.more ()) - fail (ll) << "unexpected argument '" << scan.next () << "'"; + fail (ll) << "timeout: unexpected argument '" << scan.next () << "'"; env.set_timeout (a, ops.success (), ll); } @@ -820,7 +820,7 @@ namespace build2 const string& s (*i++); if (i != e) - fail (ll) << "unexpected argument '" << *i << "'"; + fail (ll) << "exit: unexpected argument '" << *i << "'"; error (ll) << s; throw exit (false); @@ -861,23 +861,23 @@ namespace build2 set_options ops (scan); if (ops.whitespace () && ops.newline ()) - fail (ll) << "both -n|--newline and -w|--whitespace specified"; + fail (ll) << "set: both -n|--newline and -w|--whitespace specified"; if (!scan.more ()) - fail (ll) << "missing variable name"; + fail (ll) << "set: missing variable name"; string a (scan.next ()); // Either attributes or variable name. const string* ats (!scan.more () ? nullptr : &a); string vname (!scan.more () ? move (a) : scan.next ()); if (scan.more ()) - fail (ll) << "unexpected argument '" << scan.next () << "'"; + fail (ll) << "set: unexpected argument '" << scan.next () << "'"; if (ats != nullptr && ats->empty ()) - fail (ll) << "empty variable attributes"; + fail (ll) << "set: empty variable attributes"; if (vname.empty ()) - fail (ll) << "empty variable name"; + fail (ll) << "set: empty variable name"; // Read out the stream content into a string while keeping an eye on // the deadline. Then parse it according to the split mode. diff --git a/libbuild2/script/timeout.cxx b/libbuild2/script/timeout.cxx index a44e1bb..63cc61a 100644 --- a/libbuild2/script/timeout.cxx +++ b/libbuild2/script/timeout.cxx @@ -12,7 +12,10 @@ using namespace std; namespace build2 { optional - parse_timeout (const string& s, const char* what, const location& l) + parse_timeout (const string& s, + const char* what, + const char* prefix, + const location& l) { if (optional n = parse_number (s)) { @@ -21,6 +24,6 @@ namespace build2 : optional (); } else - fail (l) << "invalid " << what << " '" << s << "'" << endf; + fail (l) << prefix << "invalid " << what << " '" << s << "'" << endf; } } diff --git a/libbuild2/script/timeout.hxx b/libbuild2/script/timeout.hxx index 9991ad6..4ab43a5 100644 --- a/libbuild2/script/timeout.hxx +++ b/libbuild2/script/timeout.hxx @@ -10,12 +10,13 @@ namespace build2 { // Parse the specified in seconds timeout returning it if the value is not - // zero and nullopt otherwise. Issue diagnostics and fail if the argument is - // not a valid timeout. + // zero and nullopt otherwise. Issue diagnostics with an optional prefix and + // fail if the argument is not a valid timeout. // optional parse_timeout (const string&, const char* what, + const char* prefix = "", const location& = location ()); // As above, but return the timepoint which is away from now by the @@ -24,6 +25,7 @@ namespace build2 optional parse_deadline (const string&, const char* what, + const char* prefix = "", const location& = location ()); // Return the earlier timeout/deadline of two values, if any is present. diff --git a/libbuild2/script/timeout.ixx b/libbuild2/script/timeout.ixx index 755af17..e31ed07 100644 --- a/libbuild2/script/timeout.ixx +++ b/libbuild2/script/timeout.ixx @@ -4,9 +4,12 @@ namespace build2 { inline optional - parse_deadline (const string& s, const char* what, const location& l) + parse_deadline (const string& s, + const char* what, + const char* prefix, + const location& l) { - if (optional t = parse_timeout (s, what, l)) + if (optional t = parse_timeout (s, what, prefix, l)) return system_clock::now () + *t; else return nullopt; -- cgit v1.1