Skip to content

Commit

Permalink
Improve error-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienCassou committed Jul 29, 2024
1 parent c66a039 commit 8ef7198
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions lib/forwarder.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,33 @@ export async function forwardToDaemon(resolver, config) {
}
})
.on('end', () => {
const notForwardedContent = content.slice(0, -5);
const endOfContent = content.slice(-5);

if(fixToStdout) {
content = content.slice(-5);
}

if (content.startsWith('EXIT')) {
process.exitCode = Number(content.slice(4));
} else {
if(!endOfContent.startsWith("EXIT")) {
process.stdout.write(content);
console.error('eslint_d: unexpected response');
process.exitCode = 1;
return;
}

content = content.slice(0, -5);
const exitCode = Number(endOfContent.slice(4));
process.exitCode = exitCode;

if(exitCode !== 0 && exitCode !== 1) {
process.stdout.write(content);
return;
}

if(fixToStdout) {
const object = JSON.parse(notForwardedContent);
const output = object[0].output;
process.stdout.write(output);
if(!fixToStdout) {
return;
}

const object = JSON.parse(content);

const output = object[0].output || object[0].source;

process.stdout.write(output);
})
.on('error', async (err) => {
if (err['code'] === 'ECONNREFUSED') {
Expand Down

0 comments on commit 8ef7198

Please sign in to comment.