diff --git a/src/load_map.cpp b/src/load_map.cpp index 8371a76c7..7575cf50d 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -545,11 +545,25 @@ void map_parser::parse_style(Map & map, xml_node const& node) if (!map.insert_style(name, std::move(style))) { - if (map.find_style(name)) + boost::optional dupe = map.find_style(name); + if (strict_) { - throw config_error("duplicate style name"); + if (dupe) + { + throw config_error("duplicate style name"); + } + throw config_error("failed to insert style to the map"); + } + else + { + std::string s_err("failed to insert style '"); + s_err += name + "' to the map"; + if (dupe) + { + s_err += " since it was already added"; + } + MAPNIK_LOG_ERROR(load_map) << "map_parser: " << s_err; } - throw config_error("failed to insert style to the map"); } } catch (config_error const& ex) diff --git a/test/standalone/map_xml_test.cpp b/test/standalone/map_xml_test.cpp index d6bc6aac1..b33a3f718 100644 --- a/test/standalone/map_xml_test.cpp +++ b/test/standalone/map_xml_test.cpp @@ -156,6 +156,17 @@ TEST_CASE("map xml I/O") { } } // END SECTION + SECTION("duplicate styles only throw in strict mode") { + std::string duplicate_stylename("test/data/broken_maps/duplicate_stylename.xml"); + CAPTURE(duplicate_stylename); + mapnik::Map m(256, 256); + REQUIRE(m.register_fonts("fonts", true)); + REQUIRE_NOTHROW(mapnik::load_map(m, duplicate_stylename, false)); + mapnik::Map m2(256, 256); + REQUIRE(m2.register_fonts("fonts", true)); + REQUIRE_THROWS(mapnik::load_map(m2, duplicate_stylename, true)); + } // END SECTION + SECTION("broken maps") { std::vector broken_maps; add_xml_files("test/data/broken_maps", broken_maps);