Skip to content

Commit b2563c1

Browse files
committed
add try-catch code block
1 parent 4fdb357 commit b2563c1

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • implement-shell-tools/ls

implement-shell-tools/ls/ls.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ if (!path) {
2020
process.exit(1);
2121
}
2222

23-
const directoryContent = await fs.readdir(path);
23+
const directoryContent;
24+
25+
try {
26+
directoryContent = await fs.readdir(path);
27+
} catch (err) {
28+
console.error(`Error reading directory: ${err.message}`);
29+
process.exit(1);
30+
}
2431

2532
let allContent = directoryContent;
2633

0 commit comments

Comments
 (0)