@try/@catch operator.
See original GitHub issueProposal:
Add a try/catch operator to sass to handle @error
directives more cleanly without hard compiler crashes.
Use Case
As a developer, I’d like to be able to write test code to cover my sass functions. I’m unable to test all branches of my code as my node-sass
compiler crashes if it reaches an @error
directive. While I am glad that the @error
worked as intended and crashed while I was using the function, I’d like to be able to catch the exception during “test” mode and make an assertion about the message that was thrown.
See: https://github.com/oddbird/true/issues/92 for an example.
Side comments
With sass
as popular as it is, and new sass code being written every day, I find that the number of projects that I’ve worked on without tests for functional code to be high. Testing is necessary for maintenance and confidence in code. As sass is becoming a de-facto “language” for writing stylesheets, it seems that the @error
operator necessitates a partnering try/catch directive. Even if @error
is a weakly typed error, and try/catch doesn’t have exception types, having the ability to catch an exception and handle it (if only for testing purposes) allows me to be confident that the code that I write is working the way I intend.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:9 (3 by maintainers)
Top GitHub Comments
This is still planned, and is my next priority once we ship the new color spaces.
I started on the proposal there, and then got pulled to other things. Happy for feedback or contributions as people have time.