Skip to content

Commit f6c367c

Browse files
committed
Exit with code 1 if wc fails to read a file
1 parent d8c098f commit f6c367c

File tree

1 file changed

+5
-1
lines changed
  • implement-shell-tools/wc

1 file changed

+5
-1
lines changed

implement-shell-tools/wc/wc.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ const paths = program.args;
1717
let totalLines = 0;
1818
let totalWords = 0;
1919
let totalBytes = 0;
20+
let hadError = false;
2021

2122
for(const path of paths){
2223
let content;
2324
try{
2425
content = await fs.readFile(path, "utf-8");
2526
} catch (err){
2627
console.error(`Error reading file "${path}":`, err.message);
28+
hadError = true;
2729
continue;
2830
}
2931

@@ -62,4 +64,6 @@ if (paths.length > 1) {
6264
} else {
6365
console.log(`\t${totalLines}\t${totalWords}\t${totalBytes} total`);
6466
}
65-
}
67+
}
68+
69+
if (hadError) process.exit(1);

0 commit comments

Comments
 (0)