Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve validation error messages relating to even/odd number of arguments #6437

Open
anandthakker opened this issue Apr 2, 2018 · 4 comments
Assignees
Labels

Comments

@anandthakker
Copy link
Contributor

anandthakker commented Apr 2, 2018

When case, match, interpolate, and step don't get the right number of arguments, they produce validation errors that just say "expected odd [or even] number of arguments." We should clarify these to say something more helpful. This will probably require that we don't simply do a preflight check on the number of arguments, which means we'd have a little more wasted parsing work in the case of a validation error, but I think that's worth it.

@mmainzer
Copy link

Has there been any movement on this?

I'm trying to replicate the gl js example here: https://docs.mapbox.com/mapbox-gl-js/example/data-join/ with my own local data:

var expression = ["match", ["get", "Area"]];

// Calculate color for each state based on the unemployment rate
data.forEach(function(row) {
	var green = (row["2028 Jobs"] / maxValue) * 255;
	var color = "rgba(" + 0 + ", " + green + ", " + 0 + ", 1)";
	expression.push(row["Area"], color);
});

// Add layer from the vector tile source with data-driven style
map.addLayer({
	"id": "zips-join",
	"type": "fill",
	"source": "zip-codes",
	"source-layer": "zip-codes",
	"paint": {
		"fill-color": expression
	}
}, 'waterway-label');

However I get the following error: layers.zips-join.paint.fill-color: Expected an even number of arguments.

Not sure where to even begin

@eballeste
Copy link

eballeste commented Jul 8, 2019

stumbled across this issue #8446, the error was unintuitive because it wasn't as obvious that the zoom is an actual input and should be treated as the first argument to the step expression...

@bhison
Copy link

bhison commented Oct 23, 2019

Has there been any movement on this?

I'm trying to replicate the gl js example here: https://docs.mapbox.com/mapbox-gl-js/example/data-join/ with my own local data:

var expression = ["match", ["get", "Area"]];

// Calculate color for each state based on the unemployment rate
data.forEach(function(row) {
	var green = (row["2028 Jobs"] / maxValue) * 255;
	var color = "rgba(" + 0 + ", " + green + ", " + 0 + ", 1)";
	expression.push(row["Area"], color);
});

// Add layer from the vector tile source with data-driven style
map.addLayer({
	"id": "zips-join",
	"type": "fill",
	"source": "zip-codes",
	"source-layer": "zip-codes",
	"paint": {
		"fill-color": expression
	}
}, 'waterway-label');

However I get the following error: layers.zips-join.paint.fill-color: Expected an even number of arguments.

Not sure where to even begin

I assume you've moved on by now, but for the benefit of others coming across this, you may solve the issue by adding a final value of "" to your expression array, representing a default value.

@domlet
Copy link
Contributor

domlet commented Jul 9, 2021

I'm removing the docs label here and leaving this issue to be addressed in #9485

@domlet domlet removed the docs 📜 label Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants