Skip to content

Conversation

@mediremi
Copy link
Member

@mediremi mediremi commented Dec 24, 2025

This PR fixes an extension crash triggered by syntax errors in the current file when incremental compilation is enabled.

Background

#1167 updated compileContents to use a promisify'd version of child_process.execFile.

As mentioned in the execFile docs, it returns a rejected promise on non-zero exit codes:

If this method is invoked as its util.promisify()ed version, it returns a Promise for an Object with stdout and stderr properties. The returned ChildProcess instance is attached to the Promise as a child property. In case of an error (including any error resulting in an exit code other than 0), a rejected promise is returned, with the same error object given in the callback, but with two additional properties stdout and stderr.

However, compileContents assumes that execFile returns a resolved promise on non-zero exits:

const { stderr } = await execFilePromise(
entry.project.bscBinaryLocation,
callArgs,
{ cwd, signal },
);

and so ends up rethrowing this error (line 766):

} catch (error: any) {
if (error.name === "AbortError") {
getLogger().log(
`Compilation of ${entry.file.sourceFileName} was aborted.`,
);
} else {
getLogger().error(
`Unexpected error during compilation of ${entry.file.sourceFileName}: ${error}`,
);
throw error;
}

In turn, this makes the extension crash.

Fix

I added a .catch to check if error.stderr is non-empty, and if so return that. Otherwise, we throw the error so that we don't accidentally swallow e.g. ENOENT errors.

import { projectsFiles } from "./projectFiles";
import { getRewatchBscArgs, RewatchCompilerArgs } from "./bsc-args/rewatch";
import { BsbCompilerArgs, getBsbBscArgs } from "./bsc-args/bsb";
import { getCurrentCompilerDiagnosticsForFile } from "./server";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import was unused

@mediremi mediremi marked this pull request as ready for review December 24, 2025 20:04
@mediremi mediremi requested review from nojaf and zth December 24, 2025 20:04
@nojaf
Copy link
Member

nojaf commented Dec 24, 2025

Did you run make format?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants