Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

JS API Error object does not contain backtrace #1783

Closed
lunelson opened this issue Nov 3, 2016 · 7 comments
Closed

JS API Error object does not contain backtrace #1783

lunelson opened this issue Nov 3, 2016 · 7 comments

Comments

@lunelson
Copy link

lunelson commented Nov 3, 2016

The Error object described here in the README does not contain backtrace information in any of its properties, it only holds a reference to the file where the @error was finally generated. There were other threads about this, both here and at the libsass repo; but maybe that concerned console output and not the JS API...anyway I can't be sure if libsass is not generating the backtrace, or if node-sass is not passing it on in the Error?

#1345
sass/libsass#41

Notably, the @warn directive does produce backtrace info to the console, so the @error directive should be capable of passing it as well 😁

@lunelson lunelson changed the title Error object does not contain backtrace JS API Error object does not contain backtrace Nov 3, 2016
@lunelson
Copy link
Author

lunelson commented Nov 3, 2016

Amendment: backtrace seems to show when errors are generated by the compiler, but not when they are generated by the @error directive, i.e user code

@nschonni
Copy link
Contributor

nschonni commented Nov 8, 2016

I think these changes need to go in LibSass. I believe there might also already be an issue tracking this there.

@lunelson
Copy link
Author

lunelson commented Nov 8, 2016

@nschonni yeah I figure since a compiler error contains a backtrace, it is probably that Libsass is not generating the backtrace for @error-originated errors. I'll request they re-open the thread I mentioned above then

@benface
Copy link

benface commented Mar 30, 2017

@lunelson Any updates on this?

@lunelson
Copy link
Author

No, this is still broken. Here is a repo to isolate and demonstrate the problem:

https://github.com/lunelson/node-sass-error-trace

Clone and run npm i && npm t to see the comparison of @warn VS @error. Warnings backtrace from function to mixin to final invocation; but errors just give me the line where the error was thrown.

WARNING: this is a warning
Backtrace:
        src/_warn-fn.scss:2, in function `warn`
        src/_partial.scss:10, in mixin `warn-error-test`
        src/test.scss:7

Error: this is an error
        on line 2 of src/_error-fn.scss
>>   @error '#{$str}';
   --^

@lunelson
Copy link
Author

  1. This libsass issue from 2012 notes adding backtrace to warnings as well as errors; ironically the situation is now opposite (warnings have backtrace but errors don't)
  2. This libsass PR comment from 2015 notes backtraces being erroneously removed, then a later comment says they are restored. I reckon this happened again however, in some other PR 😐

@saper
Copy link
Member

saper commented Oct 30, 2019

This no longer happens as of node-sass 4.13.0 with libsass 3.5.5:

> node test.js

WARNING: this is a warning
         on line 2 of src/_warn-fn.scss, in function `warn`
         from line 10 of src/_partial.scss, in mixin `warn-error-test`
         from line 7 of src/test.scss

Error: this is an error
        on line 2 of src/_error-fn.scss, in function `error`
        from line 13 of src/_partial.scss, in mixin `warn-error-test`
        from line 7 of src/test.scss
>>   @error '#{$str}';

   --^

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants