Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit ec9741e

Browse files
committed
cli: error when input file is unreadable
Close #13
1 parent 085c175 commit ec9741e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

bin/cssnext

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ program.parse(process.argv)
1717

1818
var input = program.args[0] ? path.resolve(program.args[0]) : null
1919
var output = program.args[1] ? path.resolve(program.args[1]) : null
20+
if (input && !fs.existsSync(input)) {
21+
console.error(colors.red("Unable to read file"), input)
22+
process.exit(1)
23+
}
24+
2025
function transform() {
2126
require("read-file-stdin")(input, function(err, buffer) {
2227
if (err) {

test/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ test("cli", function(t) {
9999
})
100100
planned+=1
101101

102+
exec("bin/cssnext test/cli/wtf.css", function(err, stdout, stderr) {
103+
t.ok(err && err.code === 1, "should return an error when input file is unreadable")
104+
t.ok(contains(stderr, "Unable to read file"), "should show that the input file is not found")
105+
})
106+
planned+=2
107+
102108
exec("bin/cssnext test/cli/error.css", function(err, stdout, stderr) {
103109
t.ok(err && err.code === 2, "should throw an error")
104110
t.ok(contains(stderr, "encounters an error"), "should output a readable error")

0 commit comments

Comments
 (0)