dots Created with Sketch.
Yogesh Chauhan's Blog

At-rules: @error and @warn in SCSS

in SCSS on July 12, 2021

@error rule

@error rule comes in handy while using @mixin and functions and taking arguments, when you want to make sure that the arguments passed have the exact types and formats you asked for.

If that’s not the case then use @error rule to notify users about it before you move forward with the rest of the code.

The implementation is as easy as the idea itself! All you need to do is write whatever you want to print as an error after @error. Most of the time, you’d want to use a string and the passed argument to show the complete error.

SassScript will stop execution/compilation of the file after it prints the error.

@error rule example

@mixin reflexive-position($property, $value) {
  @if $property !=left and $property !=right {
    @error "Property #{$property} must be either left or right.";


.sidebar {
  @include reflexive-position(top, 12px);

It will print an error like this:

Error: "Property top must be either left or right."
3 │     @error "Property #{$property} must be either left or right.";
  │     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@warn rule

@warn rule is similar to @error rule and it comes in handy while using @mixin and functions and taking arguments. But unlike @error, you just want to discourage users from passing certain args or values.

@warn rule is really useful when showing warning to users when they pass deprecated arguments/values.

Writing @warn rule is similar to writing an @error rule.

Unlike the @error rule, the @warn rule doesn’t stop SassScript entirely.

@warn rule example

$known-prefixes: webkit,

@mixin prefix($property, $value, $prefixes) {
  @each $prefix in $prefixes {
    @if not index($known-prefixes, $prefix) {
      @warn "Unknown prefix #{$prefix}.";

.class-name {
  @include prefix(transform, rotate(15deg), abc o);

The script will execute but will show a warning like this:

Warning: Unknown prefix abc.


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Jul 22 Is there a CSS parent selector? #Jul 22 Difference between :where and :is in CSS #Jul 22 Does :is() pseudo selector hint at CSS preprocessing in the future? #Jul 22 Control Scrolling with CSS Scroll Snap #Jul 21 Control rendering using CSS content-visibility property #Jul 21 How to use @supports rule in CSS?
You might also like these
HTML Copyright SymbolHTMLHow to compress images with gulp in WordPress?WordPressWHERE Clause in PostgresPostgresHow to remove special characters (dash, asterisk etc) from any string in PHP?PHPHow to show slider value in HTML5 range input using JavaScript?HTMLCreate a responsive image gallery using CSS gridCSS