From ccb9af119e684f6fadd5eb14744e68bba9806694 Mon Sep 17 00:00:00 2001 From: David Wheatley Date: Wed, 5 Aug 2026 16:14:36 +0100 Subject: [PATCH] feat: specify layer/property that has a parse error when logging (#4292) --- src/mbgl/style/conversion/layer.cpp | 4 ++-- src/mbgl/style/layers/background_layer.cpp | 4 ++-- src/mbgl/style/layers/circle_layer.cpp | 4 ++-- src/mbgl/style/layers/color_relief_layer.cpp | 4 ++-- src/mbgl/style/layers/custom_drawable_layer.cpp | 4 ++-- src/mbgl/style/layers/custom_layer.cpp | 4 ++-- src/mbgl/style/layers/fill_extrusion_layer.cpp | 4 ++-- src/mbgl/style/layers/fill_layer.cpp | 4 ++-- src/mbgl/style/layers/heatmap_layer.cpp | 4 ++-- src/mbgl/style/layers/hillshade_layer.cpp | 4 ++-- src/mbgl/style/layers/layer.cpp.ejs | 4 ++-- src/mbgl/style/layers/line_layer.cpp | 4 ++-- src/mbgl/style/layers/location_indicator_layer.cpp | 4 ++-- src/mbgl/style/layers/raster_layer.cpp | 4 ++-- src/mbgl/style/layers/symbol_layer.cpp | 4 ++-- test/fixtures/style_parser/paint-nonobject.info.json | 2 +- 16 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/mbgl/style/conversion/layer.cpp b/src/mbgl/style/conversion/layer.cpp index 71dbf8376..b64d49033 100644 --- a/src/mbgl/style/conversion/layer.cpp +++ b/src/mbgl/style/conversion/layer.cpp @@ -27,7 +27,7 @@ std::optional setPaintProperties(Layer& layer, const Convertible& value) return std::nullopt; } if (!isObject(*paintValue)) { - return {{"paint must be an object"}}; + return {{"layer '" + layer.getID() + "': paint must be an object"}}; } return eachMember(*paintValue, [&](const std::string& k, const Convertible& v) { return layer.setProperty(k, v); }); } @@ -76,7 +76,7 @@ std::optional> Converter>::operato auto layoutValue = objectMember(value, "layout"); if (layoutValue) { if (!isObject(*layoutValue)) { - error.message = "layout must be an object"; + error.message = "layer '" + *id + "': layout must be an object"; return std::nullopt; } auto error_ = eachMember(*layoutValue, diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index d1b515d00..30002bc64 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -216,7 +216,7 @@ Value BackgroundLayer::serialize() const { std::optional BackgroundLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; + if (it == layerProperties.end()) return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; auto property = static_cast(it->second); @@ -272,7 +272,7 @@ std::optional BackgroundLayer::setPropertyInternal(const std::string& nam return std::nullopt; } - return Error{"layer doesn't support this property"}; + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty BackgroundLayer::getProperty(const std::string& name) const { diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp index edec68c4e..9d23734d2 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -516,7 +516,7 @@ Value CircleLayer::serialize() const { std::optional CircleLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; + if (it == layerProperties.end()) return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; auto property = static_cast(it->second); @@ -678,7 +678,7 @@ std::optional CircleLayer::setPropertyInternal(const std::string& name, c return std::nullopt; } - return Error{"layer doesn't support this property"}; + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty CircleLayer::getProperty(const std::string& name) const { diff --git a/src/mbgl/style/layers/color_relief_layer.cpp b/src/mbgl/style/layers/color_relief_layer.cpp index 883237f5e..99de900ec 100644 --- a/src/mbgl/style/layers/color_relief_layer.cpp +++ b/src/mbgl/style/layers/color_relief_layer.cpp @@ -181,7 +181,7 @@ Value ColorReliefLayer::serialize() const { std::optional ColorReliefLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; + if (it == layerProperties.end()) return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; auto property = static_cast(it->second); @@ -222,7 +222,7 @@ std::optional ColorReliefLayer::setPropertyInternal(const std::string& na return std::nullopt; } - return Error{"layer doesn't support this property"}; + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty ColorReliefLayer::getProperty(const std::string& name) const { diff --git a/src/mbgl/style/layers/custom_drawable_layer.cpp b/src/mbgl/style/layers/custom_drawable_layer.cpp index c4d9a7399..6867c86dc 100644 --- a/src/mbgl/style/layers/custom_drawable_layer.cpp +++ b/src/mbgl/style/layers/custom_drawable_layer.cpp @@ -69,8 +69,8 @@ std::unique_ptr CustomDrawableLayer::cloneRef(const std::string&) const { using namespace conversion; -std::optional CustomDrawableLayer::setPropertyInternal(const std::string&, const Convertible&) { - return Error{"layer doesn't support this property"}; +std::optional CustomDrawableLayer::setPropertyInternal(const std::string& name, const Convertible&) { + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty CustomDrawableLayer::getProperty(const std::string&) const { diff --git a/src/mbgl/style/layers/custom_layer.cpp b/src/mbgl/style/layers/custom_layer.cpp index 2defa0469..492d3366e 100644 --- a/src/mbgl/style/layers/custom_layer.cpp +++ b/src/mbgl/style/layers/custom_layer.cpp @@ -36,8 +36,8 @@ std::unique_ptr CustomLayer::cloneRef(const std::string&) const { using namespace conversion; -std::optional CustomLayer::setPropertyInternal(const std::string&, const Convertible&) { - return Error{"layer doesn't support this property"}; +std::optional CustomLayer::setPropertyInternal(const std::string& name, const Convertible&) { + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty CustomLayer::getProperty(const std::string&) const { diff --git a/src/mbgl/style/layers/fill_extrusion_layer.cpp b/src/mbgl/style/layers/fill_extrusion_layer.cpp index f06d6cf4f..f2936fcf2 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer.cpp +++ b/src/mbgl/style/layers/fill_extrusion_layer.cpp @@ -411,7 +411,7 @@ Value FillExtrusionLayer::serialize() const { std::optional FillExtrusionLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; + if (it == layerProperties.end()) return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; auto property = static_cast(it->second); @@ -546,7 +546,7 @@ std::optional FillExtrusionLayer::setPropertyInternal(const std::string& return std::nullopt; } - return Error{"layer doesn't support this property"}; + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty FillExtrusionLayer::getProperty(const std::string& name) const { diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index 2a0d81e23..1be6e0f0d 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -376,7 +376,7 @@ Value FillLayer::serialize() const { std::optional FillLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; + if (it == layerProperties.end()) return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; auto property = static_cast(it->second); @@ -496,7 +496,7 @@ std::optional FillLayer::setPropertyInternal(const std::string& name, con return std::nullopt; } - return Error{"layer doesn't support this property"}; + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty FillLayer::getProperty(const std::string& name) const { diff --git a/src/mbgl/style/layers/heatmap_layer.cpp b/src/mbgl/style/layers/heatmap_layer.cpp index ba9ec0c89..01e5b785f 100644 --- a/src/mbgl/style/layers/heatmap_layer.cpp +++ b/src/mbgl/style/layers/heatmap_layer.cpp @@ -288,7 +288,7 @@ Value HeatmapLayer::serialize() const { std::optional HeatmapLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; + if (it == layerProperties.end()) return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; auto property = static_cast(it->second); @@ -368,7 +368,7 @@ std::optional HeatmapLayer::setPropertyInternal(const std::string& name, return std::nullopt; } - return Error{"layer doesn't support this property"}; + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty HeatmapLayer::getProperty(const std::string& name) const { diff --git a/src/mbgl/style/layers/hillshade_layer.cpp b/src/mbgl/style/layers/hillshade_layer.cpp index e2a614353..4f4d7cac2 100644 --- a/src/mbgl/style/layers/hillshade_layer.cpp +++ b/src/mbgl/style/layers/hillshade_layer.cpp @@ -391,7 +391,7 @@ Value HillshadeLayer::serialize() const { std::optional HillshadeLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; + if (it == layerProperties.end()) return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; auto property = static_cast(it->second); @@ -516,7 +516,7 @@ std::optional HillshadeLayer::setPropertyInternal(const std::string& name return std::nullopt; } - return Error{"layer doesn't support this property"}; + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty HillshadeLayer::getProperty(const std::string& name) const { diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index c82abc93b..a39bef204 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -296,7 +296,7 @@ Value <%- camelize(type) %>Layer::serialize() const { std::optional <%- camelize(type) %>Layer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; + if (it == layerProperties.end()) return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; auto property = static_cast(it->second); @@ -349,7 +349,7 @@ std::optional <%- camelize(type) %>Layer::setPropertyInternal(const std:: return std::nullopt; } <% } %> - return Error{"layer doesn't support this property"}; + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty <%- camelize(type) %>Layer::getProperty(const std::string& name) const { diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index ce13ac28b..598292680 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -593,7 +593,7 @@ Value LineLayer::serialize() const { std::optional LineLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; + if (it == layerProperties.end()) return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; auto property = static_cast(it->second); @@ -794,7 +794,7 @@ std::optional LineLayer::setPropertyInternal(const std::string& name, con return std::nullopt; } - return Error{"layer doesn't support this property"}; + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty LineLayer::getProperty(const std::string& name) const { diff --git a/src/mbgl/style/layers/location_indicator_layer.cpp b/src/mbgl/style/layers/location_indicator_layer.cpp index b3becaa96..27c5f02e1 100644 --- a/src/mbgl/style/layers/location_indicator_layer.cpp +++ b/src/mbgl/style/layers/location_indicator_layer.cpp @@ -519,7 +519,7 @@ Value LocationIndicatorLayer::serialize() const { std::optional LocationIndicatorLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; + if (it == layerProperties.end()) return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; auto property = static_cast(it->second); @@ -678,7 +678,7 @@ std::optional LocationIndicatorLayer::setPropertyInternal(const std::stri return std::nullopt; } - return Error{"layer doesn't support this property"}; + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty LocationIndicatorLayer::getProperty(const std::string& name) const { diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index ff787a9db..9c983d595 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -391,7 +391,7 @@ Value RasterLayer::serialize() const { std::optional RasterLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; + if (it == layerProperties.end()) return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; auto property = static_cast(it->second); @@ -497,7 +497,7 @@ std::optional RasterLayer::setPropertyInternal(const std::string& name, c return std::nullopt; } - return Error{"layer doesn't support this property"}; + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty RasterLayer::getProperty(const std::string& name) const { diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 346335e36..af03e39c3 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -1419,7 +1419,7 @@ Value SymbolLayer::serialize() const { std::optional SymbolLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; + if (it == layerProperties.end()) return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; auto property = static_cast(it->second); @@ -1926,7 +1926,7 @@ std::optional SymbolLayer::setPropertyInternal(const std::string& name, c return std::nullopt; } - return Error{"layer doesn't support this property"}; + return Error{"layer '" + getID() + "' doesn't support property '" + name + "'"}; } StyleProperty SymbolLayer::getProperty(const std::string& name) const { diff --git a/test/fixtures/style_parser/paint-nonobject.info.json b/test/fixtures/style_parser/paint-nonobject.info.json index c9ae97efd..43caf4b3c 100644 --- a/test/fixtures/style_parser/paint-nonobject.info.json +++ b/test/fixtures/style_parser/paint-nonobject.info.json @@ -1,7 +1,7 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "paint must be an object"] + [1, "WARNING", "ParseStyle", "layer 'background': paint must be an object"] ] } }