Skip to content

Commit 7a2a1ae

Browse files
committed
Added error handling
1 parent 39be6f7 commit 7a2a1ae

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

gulp-cssimport.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ module.exports = function cssImport(options) {
7575
if (!isUrl(importPath)) {
7676
var pathDirectory = path.dirname(vinyl.path);
7777
var importFile = resolveImportFile(pathDirectory, importPath, options.includePaths);
78+
if (!importFile) {
79+
var err = new Error(`Cannot find file '${importPath}' from '${pathDirectory}' (includePaths: ${options.includePaths})`);
80+
callback(new gutil.PluginError(PLUGIN_NAME, err));
81+
}
7882
promises.push(readFile(importFile, "utf8").then(function(contents) {
7983
result.importFile = importFile;
8084
result.contents = contents;

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ TODO
119119

120120
CHANGELOG
121121
---------
122-
3.2 [6 Oct 2016]
122+
4.0 [6 Oct 2016]
123123
- added option 'includePaths'
124124

125125
3.0 [28 Feb 2016]

test/include-paths/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,15 @@ test("Include paths", function (t) {
2020
t.equal(data, result);
2121
t.end();
2222
});
23+
});
24+
25+
test("Include paths error", function (t) {
26+
var stream;
27+
var p = plugin({});
28+
stream = gulp.src("design/style.css")
29+
.pipe(p);
30+
collect(stream, function(err, data) {
31+
t.ok(err.message.indexOf("Cannot find file 'c.css' from") === 0);
32+
t.end();
33+
});
2334
});

test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var tests = [
1010
"options-filter",
1111
"options-matchpattern",
1212
"parent",
13+
"include-paths",
1314
"recursive"
1415
];
1516
emitter.on("run", function(index) {

0 commit comments

Comments
 (0)