summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2010-04-21 08:41:22 +0000
committerdeva <deva>2010-04-21 08:41:22 +0000
commit5ccf2327415637730d96d7520bc680301ba96e52 (patch)
tree86363ccf0474f852a2c84a8751ef7569541a65bb
parentc7705c1401bf70222b9475a1f576844437de1803 (diff)
Make extensive error handling in libartefact interface.
-rw-r--r--server/src/queryhandlerpentominos.cc56
1 files changed, 35 insertions, 21 deletions
diff --git a/server/src/queryhandlerpentominos.cc b/server/src/queryhandlerpentominos.cc
index a8d6c07..c5450b3 100644
--- a/server/src/queryhandlerpentominos.cc
+++ b/server/src/queryhandlerpentominos.cc
@@ -72,36 +72,50 @@ static QueryResult node2result(atf_result_node_t *node, time_t timestamp)
QueryResult QueryHandlerPentominos::exec(Query &query)
{
- atf_transaction_t* atft = atf_new_transaction(atfc, cpr.c_str());
+ atf_transaction_t* atft = NULL;
+ atf_reply_t *reply = NULL;
+ atf_result_t *result = NULL;
+ atf_result_node_t *root = NULL;
+ atf_status_t status;
+ time_t timestamp;
+ atf_id id;
- atf_id id = atf_add_query(atft, query.attributes["class"].c_str(),
- FILTER_LATEST, USE_NONE, 0, 0);
+ QueryResult rroot;
+ rroot.timestamp = timestamp;
+ rroot.source = "pentominos";
- atf_reply_t *reply = atf_commit(atft);
+ atft = atf_new_transaction(atfc, cpr.c_str());
+ if(!atft) goto aaarg;
- if(atf_get_num_results(reply, id) != 1) {
- // ... error ...
- }
+ id = atf_add_query(atft, query.attributes["class"].c_str(),
+ FILTER_LATEST, USE_NONE, 0, 0);
+ if(!atft) goto aaarg;
- atf_result_t *result = atf_get_result(reply, id, 0);
+ reply = atf_commit(atft);
+ if(!reply) goto aaarg;
- atf_status_t status = atf_get_result_status(result, NULL, 0);
- if(status != ATF_STATUS_OK) { return QueryResult(); }
-
- time_t timestamp = atf_get_result_timestamp(result);
+ if(atf_get_num_results(reply, id) != 1) goto aaarg;
- atf_result_node_t *root = atf_get_result_node(result);
+ result = atf_get_result(reply, id, 0);
+ if(!result) goto aaarg;
- QueryResult rroot;
- rroot.timestamp = timestamp;
- rroot.source = "pentominos";
+ status = atf_get_result_status(result, NULL, 0);
+ if(status != ATF_STATUS_OK) goto aaarg;
+
+ timestamp = atf_get_result_timestamp(result);
- QueryResult qresult = node2result(root, timestamp);
- if(root) rroot.groups[query.attributes["class"]] = qresult;
+ root = atf_get_result_node(result);
+ if(!root) goto aaarg;
+
+ {
+ QueryResult qresult = node2result(root, timestamp);
+ rroot.groups[query.attributes["class"]] = qresult;
+ }
- atf_free_result_node(root);
- atf_free_reply(reply);
- atf_free_transaction(atft);
+ aaarg:
+ if(root) atf_free_result_node(root);
+ if(reply) atf_free_reply(reply);
+ if(atft) atf_free_transaction(atft);
return rroot;
}