From cfa2ffc52e58a8de02c4acb33d298f9bcc41b33b Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 18 Apr 2012 07:37:14 -0700 Subject: [PATCH] better error output when we fail to parse comp-op or image-filters --- src/image_compositing.cpp | 7 ++++--- src/load_map.cpp | 33 ++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/image_compositing.cpp b/src/image_compositing.cpp index 722c92936..f12b38fa4 100644 --- a/src/image_compositing.cpp +++ b/src/image_compositing.cpp @@ -69,14 +69,15 @@ static const comp_op_lookup_type comp_lookup = boost::assign::list_of comp_op_from_string(std::string const& name) { + boost::optional mode; comp_op_lookup_type::right_const_iterator right_iter = comp_lookup.right.find(name); if (right_iter != comp_lookup.right.end()) { - return right_iter->second; + mode.reset(right_iter->second); } - return clear; + return mode; } template diff --git a/src/load_map.cpp b/src/load_map.cpp index a0f86bae0..0e776ff73 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -418,22 +418,34 @@ void map_parser::parse_style(Map & map, xml_node const& sty) optional comp_op_name = sty.get_opt_attr("comp-op"); if (comp_op_name) { - composite_mode_e comp_op = comp_op_from_string(*comp_op_name); - style.set_comp_op(comp_op); + optional comp_op = comp_op_from_string(*comp_op_name); + if (comp_op) + { + style.set_comp_op(*comp_op); + } + else + { + throw config_error("failed to parse comp-op: '" + *comp_op_name + "'"); + } } // image filters optional filters = sty.get_opt_attr("image-filters"); if (filters) { - std::string::const_iterator itr = (*filters).begin(); - std::string::const_iterator end = (*filters).end(); + std::string filter_mode = *filters; + if (filter_mode.empty()) + { + throw config_error("failed to parse empty image-filter"); + } + std::string::const_iterator itr = filter_mode.begin(); + std::string::const_iterator end = filter_mode.end(); mapnik::image_filter_grammar > g; bool result = boost::spirit::qi::phrase_parse(itr,end, g, boost::spirit::qi::ascii::space, style.image_filters()); if (!result || itr!=end) { - throw config_error("failed to parse:" + std::string(itr,end)); + throw config_error("failed to parse image-filter: '" + std::string(itr,end) + "'"); } } @@ -764,8 +776,15 @@ void map_parser::parse_metawriter_in_symbolizer(symbolizer_base &sym, xml_node c optional comp_op_name = pt.get_opt_attr("comp-op"); if (comp_op_name) { - composite_mode_e comp_op = comp_op_from_string(*comp_op_name); - sym.set_comp_op(comp_op); + optional comp_op = comp_op_from_string(*comp_op_name); + if (comp_op) + { + sym.set_comp_op(*comp_op); + } + else + { + throw config_error("failed to parse comp-op: '" + *comp_op_name + "'"); + } } optional transform_wkt = pt.get_opt_attr("transform");