Skip to content

Commit

Permalink
Optimize exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwkleung committed Apr 18, 2024
1 parent c464041 commit a13a4ed
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@ const chokidarPaths = [
const chokidarPathsIgnore = []

const chokidarDev = () => {
fs.open('.hmr_pid.txt', 'w', (err, fd) => {
if(!err) {
try {
fs.open('.hmr_pid.txt', 'w', (err, fd) => {
if (err) {
throw err;
}

fs.close(fd, (err) => {
if(err) {
throw console.error(err);
if (err) {
throw err;
}
})
} else {
throw console.error(err);
}
})
})
})
} catch (e) {
console.error(e);
}

console.log("HMR is active");

Expand All @@ -53,18 +57,18 @@ const chokidarDev = () => {
try {
exec('npm run build').on('exit', () => {
fs.readFile('.hmr_pid.txt', { encoding: 'utf-8' }, (err, data) => {
if(!err) {
process.kill(data);
} else {
throw console.error(err);
if (err) {
throw err;
}

process.kill(data);
})

console.log("Restarting Electron process...");
exec('npm run electron');
});
} catch(e) {
throw console.error(e);
} catch (e) {
console.error(e);
}
}
})
Expand Down

0 comments on commit a13a4ed

Please sign in to comment.