Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[ios] predicateWithMGLJSONObject: Unknown expression "!has" #14861

Closed
mfazekas opened this issue Jun 6, 2019 · 2 comments
Closed

[ios] predicateWithMGLJSONObject: Unknown expression "!has" #14861

mfazekas opened this issue Jun 6, 2019 · 2 comments

Comments

@mfazekas
Copy link

mfazekas commented Jun 6, 2019

The following code on ios:

statesLayer.predicate = [NSPredicate predicateWithMGLJSONObject: @[ @"!has", @"foo"]];

results in an exception:
"[1][0]: Unknown expression "!has". If you wanted a literal array, use ["literal", [...]]."

Steps to reproduce

statesLayer.predicate = [NSPredicate predicateWithMGLJSONObject: @[ @"!has", @"foo"]];

Expected behavior

Work as expected.

Actual behavior

Raises an exception.

2019-06-06 10:40:48.527990+0200 Mapbox GL[75351:710524] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid filter value: [1][0]: Unknown expression "!has". If you wanted a literal array, use ["literal", [...]].'
*** First throw call stack:
(
	0   CoreFoundation                      0x000000010a8e46fb __exceptionPreprocess + 331
	1   libobjc.A.dylib                     0x0000000109e88ac5 objc_exception_throw + 48
	2   CoreFoundation                      0x000000010a8e4555 +[NSException raise:format:] + 197
	3   Mapbox                              0x00000001058e7703 -[NSPredicate(MGLPrivateAdditions) mgl_filter] + 387
	4   Mapbox                              0x0000000105901a80 -[MGLFillStyleLayer setPredicate:] + 928

Notes:

  • [NSPredicate predicateWithMGLJSONObject: @[ @"!has", @"foo"]] is MGL_FUNCTION("!has", "foo") == 1
  • mgl_jsonExpressionObject retruns [==,[!has,foo],1]

This is where we set this error:

ParseResult parseCompoundExpression(const std::string name, const Convertible& value, ParsingContext& ctx) {
assert(isArray(value) && arrayLength(value) > 0);
const auto definitions = compoundExpressionRegistry.equal_range(name.c_str());
if (definitions.first == definitions.second) {
ctx.error(
R"(Unknown expression ")" + name + R"(". If you wanted a literal array, use ["literal", [...]].)",
0
);
return ParseResult();
}

Stack:

#0	0x000000010c89280f in mbgl::style::expression::parseCompoundExpression(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, mbgl::style::conversion::Convertible const&, mbgl::style::expression::ParsingContext&) at /Work/Freelance/Ruby/MlkFestival/RNMPGL/mapbox-gl-native/src/mbgl/style/expression/compound_expression.cpp:1042
#1	0x000000010c91e8ec in mbgl::style::expression::ParsingContext::parse(mbgl::style::conversion::Convertible const&, std::experimental::optional<mbgl::style::expression::TypeAnnotationOption>) at /Work/Freelance/Ruby/MlkFestival/RNMPGL/mapbox-gl-native/src/mbgl/style/expression/parsing_context.cpp:161
#2	0x000000010c91e235 in mbgl::style::expression::ParsingContext::parse(mbgl::style::conversion::Convertible const&, unsigned long, std::experimental::optional<mapbox::util::variant<mbgl::style::expression::type::NullType, mbgl::style::expression::type::NumberType, mbgl::style::expression::type::BooleanType, mbgl::style::expression::type::StringType, mbgl::style::expression::type::ColorType, mbgl::style::expression::type::ObjectType, mbgl::style::expression::type::ValueType, mapbox::util::recursive_wrapper<mbgl::style::expression::type::Array>, mbgl::style::expression::type::CollatorType, mbgl::style::expression::type::FormattedType, mbgl::style::expression::type::ErrorType> >, std::experimental::optional<mbgl::style::expression::TypeAnnotationOption>) at /Work/Freelance/Ruby/MlkFestival/RNMPGL/mapbox-gl-native/src/mbgl/style/expression/parsing_context.cpp:88
#3	0x000000010c886646 in mbgl::style::expression::parseComparison(mbgl::style::conversion::Convertible const&, mbgl::style::expression::ParsingContext&) at /Work/Freelance/Ruby/MlkFestival/RNMPGL/mapbox-gl-native/src/mbgl/style/expression/comparison.cpp:221
#4	0x000000010c91e86b in mbgl::style::expression::ParsingContext::parse(mbgl::style::conversion::Convertible const&, std::experimental::optional<mbgl::style::expression::TypeAnnotationOption>) at /Work/Freelance/Ruby/MlkFestival/RNMPGL/mapbox-gl-native/src/mbgl/style/expression/parsing_context.cpp:159
#5	0x000000010c92102f in mbgl::style::expression::ParsingContext::parseExpression(mbgl::style::conversion::Convertible const&, std::experimental::optional<mbgl::style::expression::TypeAnnotationOption>) at /Work/Freelance/Ruby/MlkFestival/RNMPGL/mapbox-gl-native/src/mbgl/style/expression/parsing_context.cpp:229
#6	0x000000010c7cea32 in mbgl::style::conversion::Converter<mbgl::style::Filter, void>::operator()(mbgl::style::conversion::Convertible const&, mbgl::style::conversion::Error&) const at /Work/Freelance/Ruby/MlkFestival/RNMPGL/mapbox-gl-native/src/mbgl/style/conversion/filter.cpp:23
#7	0x000000010c2e18f8 in std::experimental::optional<mbgl::style::Filter> mbgl::style::conversion::convert<mbgl::style::Filter>(mbgl::style::conversion::Convertible const&, mbgl::style::conversion::Error&) at /Work/Freelance/Ruby/MlkFestival/RNMPGL/mapbox-gl-native/include/mbgl/style/conversion_impl.hpp:286
#8	0x000000010c2e1627 in ::-[NSPredicate(MGLPrivateAdditions) mgl_filter]() at /Work/Freelance/Ruby/MlkFestival/RNMPGL/mapbox-gl-native/platform/darwin/src/NSPredicate+MGLAdditions.mm:15
#9	0x000000010c2fba80 in ::-[MGLFillStyleLayer setPredicate:](NSPredicate *) at /Work/Freelance/Ruby/MlkFestival/RNMPGL/mapbox-gl-native/platform/darwin/src/MGLFillStyleLayer.mm:74

As a workaround
[NSPredicate predicateWithMGLJSONObject: @[ @"!",@[@"has", @"foo"]]]

Configuration

Mapbox SDK versions: 198ed88 - 5.1.0.alpha1
iOS/macOS versions: 12.2/10.14.4
Device/simulator models: iPhone X
Xcode version: 10.2.1

@1ec5
Copy link
Contributor

1ec5 commented Jun 6, 2019

!has is part of the filter syntax in the style specification. Filters are deprecated and are no longer supported in the native SDKs. Instead, wrap a has expression inside a ! expression.

@1ec5 1ec5 closed this as completed Jun 6, 2019
@mfazekas
Copy link
Author

mfazekas commented Jun 7, 2019

@1ec5 thanks, i was just searching for '!has' in docs and was confused by avaiability, as it statediOS > 3.3.0. I have not noticed it's in the filter part of docs.

kép

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants