-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to log a warning instead of throwing an exception
If we made it an exception, SDKs could catch it and provide platform-native error response.
src/mbgl/style/style.cpp
Outdated
@@ -158,7 +158,30 @@ void Style::addSource(std::unique_ptr<Source> source) { | |||
sources.emplace_back(std::move(source)); | |||
} | |||
|
|||
struct SourceIdUsageEvaluator { | |||
std::string sourceId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be const, or even a const ref
src/mbgl/style/style.cpp
Outdated
}); | ||
|
||
if (layerIt != layers.end()) { | ||
Log::Warning(Event::General, "Source %s is in use, cannot remove", id.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we please add quotes around the name?
2dea1db
to
7a67bd1
Compare
Agreed, but we also force the SDKs to deal with it. Not sure if it's that helpful. We now have a mix of exception / log and ignore. We should align that at some point I had to add a default case to |
include/mbgl/style/layer.hpp
Outdated
@@ -88,6 +89,8 @@ class Layer : public mbgl::util::noncopyable { | |||
return std::forward<V>(visitor)(*as<CustomLayer>()); | |||
case LayerType::FillExtrusion: | |||
return std::forward<V>(visitor)(*as<FillExtrusionLayer>()); | |||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding default
means that clang won't issue an "enumeration value not handled in switch" error if you add a new layer type enum but forget to add it here. Use this convention instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Although returning a nullptr
is not an option here. I couldn't find a good way to return in all instantiations (eg. for void
, stack based values and pointers), so I kept the runtime_error to appease gcc.
|
||
if (layerIt != layers.end()) { | ||
Log::Warning(Event::General, "Source '%s' is in use, cannot remove", id.c_str()); | ||
return nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are SDKs prepared for removeSource
returning a null pointer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jfirebaugh Yes, a nullptr
was already returned in case the source doesn't exist here. I've added tests for the Android and iOS/macos SDKs to ensure this.
7a67bd1
to
9f7aad7
Compare
Closes #9121
I opted to log a warning instead of throwing an exception. I can see it going both ways though.