style-dictionary icon indicating copy to clipboard operation
style-dictionary copied to clipboard

Style Dictionary crashes with generic error "Name must be a string" when there is a design token without a name

Open d49017 opened this issue 4 months ago • 3 comments

When there is a design token that happens to not have any name, so for example it looks like this { "": { "value": "#", "type": "color" } }, the style dictionary crashes with a really generic error "Name must be a string" which is not helpful at all. I was only able to find this by removing tokens one-by-one.

It would be helpful to know a bit more about the problematic token, like for example where it is (JSONPath or at least line and column), "how it looks like" or what is the exact problem. Would it possible to improve error messages a bit?

node version: 18.14.2 npm version: 9.5.0 style-dictionary version: 3.9.2

d49017 avatar Feb 08 '24 14:02 d49017

I think we can improve some of the logs indeed by at least telling the user the filePath of the offending token so it's easier to find. If the token doesn't have a name, it's a bit tricky to tell the user which token has the issue though :\

jorenbroekema avatar May 01 '24 17:05 jorenbroekema

If the token doesn't have a name, it's a bit tricky to tell the user which token has the issue though :\

That's why I mentioned JSONPath, for example an error may indicate that there is a problem in a child token that is inside the parent accessible under the path a.b.c.d.

d49017 avatar May 07 '24 10:05 d49017

True, we can use token.path.join('.'), PRs welcome! as of writing, use the v4 branch for now, if that branch no longer exists it means 4.0.0 has been released and the main branch can be used instead.

jorenbroekema avatar May 07 '24 11:05 jorenbroekema