aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-05-16 16:05:05 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-05-16 16:28:12 +0300
commit320e849d17597aef40b9e3e62f79319f13f97e45 (patch)
tree9d6e4254c5461bfd3547aa4aa2d21057f77ee1b9
parent5d54628076bd7fc97e90c81b6d0df0fef4ceae20 (diff)
Fix uncaught invalid_path exception
-rw-r--r--build2/algorithm.cxx4
-rw-r--r--build2/b.cxx2
-rw-r--r--build2/cc/common.cxx5
-rw-r--r--build2/parser.cxx30
-rw-r--r--build2/scope.cxx12
-rw-r--r--build2/scope.hxx2
6 files changed, 37 insertions, 18 deletions
diff --git a/build2/algorithm.cxx b/build2/algorithm.cxx
index f695c74..ba9f5bc 100644
--- a/build2/algorithm.cxx
+++ b/build2/algorithm.cxx
@@ -50,7 +50,7 @@ namespace build2
assert (phase == run_phase::match);
optional<string> ext;
- const target_type* tt (s.find_target_type (n, ext));
+ const target_type* tt (s.find_target_type (n, ext, location ()));
if (tt == nullptr)
fail << "unknown target type " << n.type << " in name " << n;
@@ -78,7 +78,7 @@ namespace build2
name n (cn);
optional<string> ext;
- const target_type* tt (s.find_target_type (n, ext));
+ const target_type* tt (s.find_target_type (n, ext, location ()));
// For now we treat an unknown target type as an unknown target. Seems
// logical.
diff --git a/build2/b.cxx b/build2/b.cxx
index 70fb470..89929b1 100644
--- a/build2/b.cxx
+++ b/build2/b.cxx
@@ -1263,7 +1263,7 @@ main (int argc, char* argv[])
// Find the target type and extract the extension.
//
optional<string> e;
- const target_type* ti (bs.find_target_type (tn, e));
+ const target_type* ti (bs.find_target_type (tn, e, l));
if (ti == nullptr)
fail (l) << "unknown target type " << tn.type;
diff --git a/build2/cc/common.cxx b/build2/cc/common.cxx
index e4dbfe8..c32d83e 100644
--- a/build2/cc/common.cxx
+++ b/build2/cc/common.cxx
@@ -429,7 +429,10 @@ namespace build2
// This is import.
//
optional<string> ext;
- const target_type* tt (s.find_target_type (n, ext)); // Changes name.
+
+ // Changes name.
+ //
+ const target_type* tt (s.find_target_type (n, ext, location ()));
if (tt == nullptr)
fail << "unknown target type '" << n.type << "' in library " << n;
diff --git a/build2/parser.cxx b/build2/parser.cxx
index 96465f6..bbce5e5 100644
--- a/build2/parser.cxx
+++ b/build2/parser.cxx
@@ -150,7 +150,7 @@ namespace build2
const location& loc)
{
optional<string> e;
- const target_type* ti (p.scope_->find_target_type (n, e));
+ const target_type* ti (p.scope_->find_target_type (n, e, loc));
if (ti == nullptr)
p.fail (loc) << "unknown target type " << n.type;
@@ -735,7 +735,7 @@ namespace build2
for (auto& pn: pns)
{
optional<string> e;
- const target_type* ti (scope_->find_target_type (pn, e));
+ const target_type* ti (scope_->find_target_type (pn, e, ploc));
if (ti == nullptr)
fail (ploc) << "unknown target type " << pn.type;
@@ -3104,19 +3104,27 @@ namespace build2
<< " pattern";
}
- if (s == '+')
+ try
{
- if (p)
- include_pattern (move (v), a);
+ if (s == '+')
+ {
+ if (p)
+ include_pattern (move (v), a);
+ else
+ include_match (move (v), a);
+ }
else
- include_match (move (v), a);
+ {
+ if (p)
+ exclude_pattern (move (v));
+ else
+ exclude_match (v);
+ }
}
- else
+ catch (const invalid_path& e)
{
- if (p)
- exclude_pattern (move (v));
- else
- exclude_match (v);
+ fail (l) << "invalid path '" << e.path << "' in " << what
+ << " pattern";
}
}
diff --git a/build2/scope.cxx b/build2/scope.cxx
index a15eeba..e5762f1 100644
--- a/build2/scope.cxx
+++ b/build2/scope.cxx
@@ -569,7 +569,7 @@ namespace build2
static const string file_tt ("file");
const target_type* scope::
- find_target_type (name& n, optional<string>& ext) const
+ find_target_type (name& n, optional<string>& ext, const location& loc) const
{
ext = nullopt;
@@ -622,7 +622,15 @@ namespace build2
if (i != string::npos)
{
- n.dir /= dir_path (v, i != 0 ? i : 1); // Special case: "/".
+ try
+ {
+ n.dir /= dir_path (v, i != 0 ? i : 1); // Special case: "/".
+ }
+ catch (const invalid_path& e)
+ {
+ fail (loc) << "invalid path '" << e.path << "'";
+ }
+
v = string (v, i + 1, string::npos);
}
diff --git a/build2/scope.hxx b/build2/scope.hxx
index 0bfd76e..527ff86 100644
--- a/build2/scope.hxx
+++ b/build2/scope.hxx
@@ -218,7 +218,7 @@ namespace build2
// necessarily normalized). Return NULL if not found.
//
const target_type*
- find_target_type (name&, optional<string>& ext) const;
+ find_target_type (name&, optional<string>& ext, const location&) const;
// Dynamically derive a new target type from an existing one. Return the
// reference to the target type and an indicator of whether it was