question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@try/@catch operator.

See original GitHub issue

Proposal:

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:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mirisuzannecommented, Oct 28, 2022

This is still planned, and is my next priority once we ship the new color spaces.

1reaction
mirisuzannecommented, May 21, 2020

I started on the proposal there, and then got pulled to other things. Happy for feedback or contributions as people have time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

tryCatch(_:) | Apple Developer Documentation
operator evaluates to ensure the values are greater than zero. If the values aren't greater than zero, the operator throws an error to...
Read more >
try...catch - JavaScript - MDN Web Docs - Mozilla
The try...catch statement is comprised of a try block and either a catch block, a finally block, or both. The code in the...
Read more >
Error handling, "try...catch" - The Modern JavaScript Tutorial
To unify error handling, we'll use the throw operator. “Throw” operator. The throw operator generates an error. The syntax is:.
Read more >
try-catch - C# Reference - Microsoft Learn
The try-catch statement consists of a try block followed by one or more catch clauses, which specify handlers for different exceptions.
Read more >
Exceptions and debugging - Advanced R. - Hadley Wickham
tryCatch () is a general tool for handling conditions: in addition to errors, you can take different actions for warnings, messages, and interrupts....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found