Skip to content

Errors while executing compiler are not caught correctly #16

@nandenjin

Description

@nandenjin

How to reproduce

Use this loader without emsdk

Expected

An error will be thrown by utility.getDependencies().

const { stdout } = await execute(compiler, [
...flags,
'-MM',
absPath,
]).catch(err => {
throw err.err;
});

What happened

It doesn't throw anything and returns an empty array. As a result, utility.getLatestModifiedTime() throws an error:

ERROR in ./src/main.clist
Module build failed (from ../../emcc-loader/lib/index.js):
Error: paths must be non-empty.
    at getLatestModifiedTime (/Users/nandenjin/workspace/emcc-loader/lib/index.js:63:15)
    at Compiler.compile (/Users/nandenjin/workspace/emcc-loader/lib/index.js:230:42)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Compiler.process (/Users/nandenjin/workspace/emcc-loader/lib/index.js:203:30)
 @ ./src/index.ts 12:0-34 30:22-39

How to fix

utility.execute() is designed that it passes error as its return value instead of throwing it.

emcc-loader/src/utility.ts

Lines 98 to 118 in 2a3c0ba

return new Promise<SuccessType>((resolve, reject) => {
childProcess.execFile(
childProcessExecutable,
childProcessArguments,
options || {},
(err, stdout, stderr) => {
if (err) {
resolve({
err,
stdout,
stderr,
});
} else {
resolve({
stdout,
stderr,
});
}
}
);
});

So, it may be fixed with detecting errors with return value instead of using .catch()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions