Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors from execute() by its returning values #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ export class Compiler {
}

await utility.mkdirs(path.dirname(outputPath), undefined);
const { stderr } = await utility
.execute(compiler, [...flags, '-c', '-o', outputPath, srcPath])
.catch(err => {
if (err.err.code === 'ENOENT') {
throw new Error(
`Not found '${compiler}. Have you install it?'`
);
}
return { stderr: err.stderr as string | Buffer };
});
const { stderr, err } = await utility.execute(compiler, [
...flags,
'-c',
'-o',
outputPath,
srcPath,
]);

if (err) throw err;

return message.parseClangMessage(stderr.toString());
}

Expand Down Expand Up @@ -165,16 +165,10 @@ export class Compiler {
flags.unshift('--post-js', options.postJs);
}
await utility.mkdirs(path.dirname(outputPath), undefined);
const { stderr } = await utility
.execute(options.ld, flags)
.catch(err => {
if (err.err.code === 'ENOENT') {
throw new Error(
`Not found '${options.ld}. Have you install it?'`
);
}
return { stderr: err.stderr as string | Buffer };
});
const { stderr, err } = await utility.execute(options.ld, flags);

if (err) throw err;

return message.parseClangMessage(stderr.toString());
}

Expand Down
11 changes: 4 additions & 7 deletions src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ export async function getDependencies(
absPath: string,
flags: string[]
) {
const { stdout } = await execute(compiler, [
...flags,
'-MM',
absPath,
]).catch(err => {
throw err.err;
});
const { stdout, err } = await execute(compiler, [...flags, '-MM', absPath]);

if (err) throw err;

const dependencies = stdout
.toString()
.trim()
Expand Down