Permalink
Browse files

Better error message propagation to client.

  • Loading branch information...
1 parent 04fb2aa commit 345b1b8905c8353fab6e381b24bef0811f3adb76 @mavam mavam committed Aug 2, 2012
Showing with 25 additions and 17 deletions.
  1. +4 −4 src/vast/exception.cc
  2. +2 −2 src/vast/exception.h
  3. +2 −2 src/vast/expression.cc
  4. +10 −5 src/vast/query.cc
  5. +7 −4 src/vast/query_client.cc
View
@@ -60,17 +60,17 @@ query::query(char const* msg)
{
}
-syntax::syntax(char const* msg, std::string const& q)
+syntax::syntax(std::string const& q)
{
std::ostringstream oss;
- oss << "syntax error: " << msg << " (query: " << q << ')';
+ oss << "syntax error in '" << q << "'";
msg_ = oss.str();
}
-semantic::semantic(char const* msg, std::string const& q)
+semantic::semantic(std::string const& q)
{
std::ostringstream oss;
- oss << "semantic error: " << msg << " (query: " << q << ')';
+ oss << "semantic error in '" << q << "'";
msg_ = oss.str();
}
View
@@ -63,13 +63,13 @@ struct query : public exception
/// Thrown when a syntax error with a query occurs.
struct syntax : public query
{
- syntax(char const* msg, std::string const& q);
+ syntax(std::string const& q);
};
/// Thrown when a semantic error with a query occurs.
struct semantic : public query
{
- semantic(char const* msg, std::string const& q);
+ semantic(std::string const& q);
};
} // namespace error
View
@@ -488,10 +488,10 @@ void expression::parse(std::string str)
detail::ast::query ast;
if (! util::parser::parse<detail::parser::query>(str_, ast))
- throw error::syntax("parse error", str_);
+ throw error::syntax(str_);
if (! detail::ast::validate(ast))
- throw error::semantic("parse error", str_);
+ throw error::semantic(str_);
if (ast.rest.empty())
{
View
@@ -87,16 +87,21 @@ query::query(cppa::actor_ptr archive,
}
catch (error::syntax const& e)
{
- LOG(error, query)
- << "syntax error in query @" << id() << ": " << e.what();
+ std::stringstream msg;
+ msg << "query @" << id() << " is invalid: " << e.what();
+
+ LOG(error, query) << msg.str();
+ reply(atom("set"), atom("expression"), atom("failure"), msg.str());
}
catch (error::semantic const& e)
{
- LOG(error, query)
- << "semantic error in query @" << id() << ": " << e.what();
+ std::stringstream msg;
+ msg << "query @" << id() << " is invalid: " << e.what();
+
+ LOG(error, query) << msg.str();
+ reply(atom("set"), atom("expression"), atom("failure"), msg.str());
}
- reply(atom("set"), atom("expression"), atom("failure"));
},
on(atom("set"), atom("batch size"), arg_match) >> [=](unsigned batch_size)
{
View
@@ -114,25 +114,28 @@ void query_client::set_expression()
send(query_, atom("set"), atom("expression"), expression_);
become(
keep_behavior,
- on(atom("set"), atom("expression"), atom("failure")) >> [=]
+ on(atom("set"), atom("expression"), atom("failure"), arg_match)
+ >> [=](std::string const& msg)
{
- unbecome(); // TODO: remove after sync_send fix.
+ LOG(error, query) << msg;
+
+ unbecome();
send(self, atom("shutdown"));
},
on(atom("set"), atom("expression"), atom("success")) >> [=]
{
LOG(info, query) << "query client @" << id()
<< " successfully set expression '" << expression_ << "'";
- unbecome(); // TODO: remove after sync_send fix.
+ unbecome();
send(query_, atom("start"));
},
after(std::chrono::seconds(1)) >> [=]
{
LOG(info, query) << "query client @" << id()
<< " timed out trying to set expression: " << expression_;
- unbecome(); // TODO: remove after sync_send fix.
+ unbecome();
send(self, atom("shutdown"));
});
}

0 comments on commit 345b1b8

Please sign in to comment.