Skip to content

Commit 9139868

Browse files
committed
fix cat error handler
1 parent e785ce0 commit 9139868

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

implement-shell-tools/cat/cat.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ program.parse();
1313
const options = program.opts();
1414
const paths = program.args;
1515

16+
let hadError = false;
1617
for(const path of paths){
1718
let content;
1819
try {
1920
content = await fs.readFile(path, "utf-8")
2021
} catch(err) {
2122
console.error(`Error reading file "${path}": ${err.message} `);
23+
hadError = true;
2224
continue;
2325
}
2426

2527
// split file into lines
2628
let lines = content.replace(/\n$/, "").split("\n");
27-
2829
let lineNum = 1;
2930

3031
for (const line of lines){
@@ -42,4 +43,6 @@ for(const path of paths){
4243
console.log(`${line}`)
4344
}
4445
}
45-
}
46+
}
47+
48+
if (hadError) process.exit(1);

0 commit comments

Comments
 (0)