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

ERROR: Maximum call stack size exceeded when using json/nested #464

Closed
lukasoppermann opened this issue Sep 28, 2020 · 7 comments
Closed

Comments

@lukasoppermann
Copy link
Contributor

lukasoppermann commented Sep 28, 2020

Hey, I am getting the following error when trying to transform my json file. I am a bit at a loss what to do about it. 😅

Please let me know how I can provide some more helpful information.

/Users/lukasoppermann/Repos/design-token-transformer/node_modules/style-dictionary/lib/common/formats.js:75
if (obj.hasOwnProperty('value')) {
^

RangeError: Maximum call stack size exceeded
at String.hasOwnProperty ()
at minifyDictionary (/Users/lukasoppermann/Repos/design-token-transformer/node_modules/style-dictionary/lib/common/formats.js:75:11)
at minifyDictionary (/Users/lukasoppermann/Repos/design-token-transformer/node_modules/style-dictionary/lib/common/formats.js:80:23)
at minifyDictionary (/Users/lukasoppermann/Repos/design-token-transformer/node_modules/style-dictionary/lib/common/formats.js:80:23)
at minifyDictionary (/Users/lukasoppermann/Repos/design-token-transformer/node_modules/style-dictionary/lib/common/formats.js:80:23)
at minifyDictionary (/Users/lukasoppermann/Repos/design-token-transformer/node_modules/style-dictionary/lib/common/formats.js:80:23)
at minifyDictionary (/Users/lukasoppermann/Repos/design-token-transformer/node_modules/style-dictionary/lib/common/formats.js:80:23)
at minifyDictionary (/Users/lukasoppermann/Repos/design-token-transformer/node_modules/style-dictionary/lib/common/formats.js:80:23)
at minifyDictionary (/Users/lukasoppermann/Repos/design-token-transformer/node_modules/style-dictionary/lib/common/formats.js:80:23)
at minifyDictionary (/Users/lukasoppermann/Repos/design-token-transformer/node_modules/style-dictionary/lib/common/formats.js:80:23)

@chazzmoney
Copy link
Collaborator

chazzmoney commented Sep 28, 2020

@lukasoppermann
Looks like there may be an infinite loop in the recursive minification. Based on the function it is calling, there may be a circular reference in the dictionary you are supplying:

function minifyDictionary(obj) {
  var toRet = {};
  if (obj.hasOwnProperty('value')) {
    return obj.value;
  } else {
    for(var name in obj) {
      if(obj.hasOwnProperty(name)) {
        toRet[name] = minifyDictionary(obj[name]);
      }
    }
  }
  return toRet;
}

@dbanksdesign if there is a circular reference issue possibility here, it might be worth for us to catch the "RangeError: Maximum call stack size exceeded" error and output a line telling people they have a circular reference as an error / failure.... if we can even catch that.

@lukasoppermann
Copy link
Contributor Author

I think I have found what causes it, in the json below the comment key on line 3 (as a child of the h3) causes the issue. Removing this makes it work. However having additional comments & meta info on a group is important for documenting the system.

"body": {
    "h3": {
      "comment": "Comment for text style",
      "fontSize": {
        "value": 20,
        "type": "number",
        "unit": "pixel"
      },
      "textDecoration": {
        "value": "none",
        "type": "string"
      }, //…

@dbanksdesign
Copy link
Member

Found the issue and opened a PR for it: #465

@chazzmoney
Copy link
Collaborator

@dbanksdesign while it looks like we have a solution for the issue now, it still stands that there may be another data state in which an infinite loop could occur here. Do we want to try to catch that?

@dbanksdesign
Copy link
Member

Good call. I'll try to think of other cases that would result in an infinite loop...

@dbanksdesign
Copy link
Member

This is now merged and released in v2.10.2!

@lukasoppermann
Copy link
Contributor Author

Thank you!

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

No branches or pull requests

3 participants