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

Add documentation about correct way of handling non-existent content in importer function #697

Closed
ubenzer opened this issue Feb 23, 2015 · 2 comments

Comments

@ubenzer
Copy link

ubenzer commented Feb 23, 2015

Hello,

I am trying to use node-saas with custom importer function. The reason I am doing this is, I don't directly read from file, instead I am compiling saas from in-memory strings.

In importer function,
in case I can't find the partial how should I handle this error so it fails gracefully?
https://github.com/sass/node-sass#importer-starting-from-v2

Should I return null; or done(null); ? Or should I simply throw a new Error("File not found") ?

@am11
Copy link
Contributor

am11 commented Feb 23, 2015

Would you like to send a PR based on your findings and the discussion that transpired here: #615?

@am11 am11 added this to the Unknown milestone Mar 5, 2015
am11 added a commit that referenced this issue Apr 11, 2015
@am11
Copy link
Contributor

am11 commented Apr 11, 2015

This is fixed by c481f30.

The new implementation (#817) lets you use the API as follow:

var sass = require('node-sass');

var options = {
  file: 'path/to/file.scss',
  importer: functions (url, prev, done) {

      try {
        var response = {
        file: processPaths(url, prev)
        };
        done(response)
      } catch (_) {
        done(new Error('my faviourite error message'));
      }
  }
};

sass.render(options, function (err, response) {
  if (err) {
    console.error(err); return;
  }
});

@am11 am11 closed this as completed Apr 11, 2015
@xzyfer xzyfer removed this from the Unknown milestone Sep 17, 2015
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

3 participants