sindresorhus / grunt-sass

Compile Sass to CSS
MIT License
1.01k stars 209 forks source link

Add file, line and column to error message #290

Closed skinnomecom closed 5 years ago

skinnomecom commented 6 years ago

Optimizes error output and by that simplifies bug fixing.

Before: Fatal error: Incompatible units: 'px' and 'Px'.

Now: Fatal error: Incompatible units: 'px' and 'Px'. /Users/******/sass/*****/_test.scss (7:13)

sindresorhus commented 6 years ago

I think this should be fixed in the node-sass and dart-sass instead. That way all plugins would benefit from increased information instead of just working around it here.

// @nex3

sindresorhus commented 6 years ago

The format should be /Users/******/sass/*****/_test.scss:7:13 so you can Command+click the line to open it in many terminals.

nex3 commented 6 years ago

cc @xzyfer

Dart Sass just matches Node Sass's format for messages. I believe there's a formatted field or something on the error that you can use to get more detailed output, but I don't know what it is off the top of my head.

badfeather commented 6 years ago

The format should be /Users/******/sass/*****/_test.scss:7:13 so you can Command+click the line to open it in many terminals.

So in other words, it should be changed to: grunt.fatal(${err.message}\n${err.file}:${err.line}:${err.column});

Correct? Happy to create a pull request, unless @skinnomecom wants to make the edit.

martinfojtik commented 5 years ago

i think better sollution is update catch like this

catch((error) => {
            if (typeof error.formatted !== 'undefined') {
                grunt.log.error(error.formatted);
            } else {
                grunt.log.error(error);
            }

            done(error);
        })
badfeather commented 5 years ago

@martinfojtik In testing your code, it looks like it stops the rest of the gruntfile from executing.

sindresorhus commented 5 years ago

Closing for lack of activity. PR welcome if anyone wants to fix this properly.