amzn / style-dictionary

A build system for creating cross-platform styles.
https://amzn.github.io/style-dictionary/#/
Apache License 2.0
3.74k stars 524 forks source link

Catching Errors with Node modules #1237

Open adrianstainforth-reachplc opened 3 weeks ago

adrianstainforth-reachplc commented 3 weeks ago

So we have an issue with

const SD = StyleDictionary.extend({
            source: [outputJson],
            platforms: {
              css: {
                transformGroup: 'css',
                files: [
                  {
                    destination: outputCss,
                    format: 'css/variables',
                  },
                ],
              },
            },
          });

SD.buildPlatform('css');

But it's generating this error:

While building public/assets/liverpoolecho/tokens/xl.4d18589fd52b6b24.css, token collisions were found; output may be unexpected.
    Output name molecule-ace-signposting-info-more-icon-fill-border-color was generated by:
        molecule.ACE.Signposting.info.more.icon-fill.borderColor   #3D3F40
        molecule.ACE.Signposting.info.more.icon-fill.border.color   #3D3F40
This many-to-one issue is usually caused by some combination of:
    * conflicting or similar paths/names in property definitions
    * platform transforms/transformGroups affecting names, especially when removing specificity
    * overly inclusive file filters

However there seems to be no way to catch the error and handle it. I like to stop the build but that does not seem possible even wrapping in try...catch.

Is there anyway to handle it or is there anything in the pipeline to handle it?

adrianstainforth-reachplc commented 3 weeks ago

I can see in here - https://github.com/amzn/style-dictionary/blob/17f4cb2f30bd002dfd55d6ef8c5bee4138de8d64/lib/buildFile.js#L59

that any issue is just console.log

Could we add something the extend that allowed you set the config in extend to throw errors or something?

jorenbroekema commented 2 weeks ago

In version 4 you will be able to control the logging more granularly.

https://v4.styledictionary.com/reference/logging/ It allows you to throw errors when warnings occur allowing you to catch them. Also allows toggling the verbosity of the logs or silence warnings and/or success logs altogether

Note that you do need to check out the migration guidelines in order to migrate to the v4 prerelease (as of writing that's 4.0.0-prerelease.35)