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

Build errors don't always specify style #28

Open
aparlato opened this issue Sep 18, 2024 · 0 comments
Open

Build errors don't always specify style #28

aparlato opened this issue Sep 18, 2024 · 0 comments

Comments

@aparlato
Copy link
Contributor

aparlato commented Sep 18, 2024

Sometimes we hit errors that aren't very specific about where/how to solve. See error below:

(repo & layer id redacted for privacy reasons)

[nodemon] starting `scripts/build-styles.sh && yarn clean-styles`
Building styles
Error: Couldn't build layer <layerID>.

Details: Cannot read properties of undefined (reading 'low') in
  <repo>/templates/layers/<layerID>.js

30:         context.colors.landuse.desert.low,

In this case, the error is a JS error as opposed to being build system specific. As we can't catch all JS related errors, it would be helpful to be aware of what style is processing when this happens.

Additional context

While not necessarily relevant for this issue in providing style names at the right time during build, for those curious the issue above is explained here:

The erroring styles don't have the variable for landuse.desert.low, but there's a JS tolerance issue here. Basically, it just returns undefined if the final key isn't present on an object, but if it's trying to find a key on something that isn't an object but is instead undefined, it errors because that syntax doesn't make sense for it.

In this case, the landuse object doesn't contain desert or desert.low. If we only used landuse.desert it would return undefined and move on, but since it's trying to find a key on undefined it fails.

To handle that and still return undefined, we'd need to use optional chaining like context.colors.landuse?.desert?.low so it would cut itself short on the first undefined.

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

1 participant