Skip to content
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
21 changes: 15 additions & 6 deletions src/conductor/runner/BasicEvaluator.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { ConductorInternalError } from "../../common/errors";
import { RunnerStatus } from "../types";
import type { IEvaluator, IRunnerPlugin } from "./types";

export abstract class BasicEvaluator implements IEvaluator {
readonly conductor: IRunnerPlugin;

async startEvaluator(entryPoint: string): Promise<void> {
const initialChunk = await this.conductor.requestFile(entryPoint);
if (!initialChunk) throw new ConductorInternalError("Cannot load entrypoint file");
this.conductor.sendResult(await this.evaluateFile(entryPoint, initialChunk));
while (true) {
const chunk = await this.conductor.requestChunk();
this.conductor.sendResult(await this.evaluateChunk(chunk));
try {
const initialChunk = await this.conductor.requestFile(entryPoint);
if (!initialChunk) throw new ConductorInternalError("Cannot load entrypoint file");
this.conductor.sendResult(await this.evaluateFile(entryPoint, initialChunk));
while (true) {
const chunk = await this.conductor.requestChunk();
this.conductor.sendResult(await this.evaluateChunk(chunk));
}
// The REPL loop only exits if the conduit is terminated externally.
this.conductor.updateStatus(RunnerStatus.STOPPED, true);
Comment on lines +17 to +18

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This code is unreachable because of the preceding infinite while (true) loop. If allowUnreachableCode is disabled in tsconfig.json, this will also cause a compilation error. Since the loop never terminates normally, these lines should be removed.

} catch (e) {
// Always notify the host so it can unblock its own REPL loop.
this.conductor.updateStatus(RunnerStatus.ERROR, true);
throw e;
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/conductor/runner/RunnerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ export class RunnerPlugin implements IRunnerPlugin {
console.error(`Host expects at least protocol version ${message.data.minVersion}, but we are on version ${Constant.PROTOCOL_VERSION}`);
this.__conduit.terminate();
}],
[ServiceMessageType.ENTRY, function entryServiceHandler(this: RunnerPlugin, message: EntryServiceMessage) {
this.__evaluator.startEvaluator(message.data);
[ServiceMessageType.ENTRY, async function entryServiceHandler(this: RunnerPlugin, message: EntryServiceMessage) {
try {
await this.__evaluator.startEvaluator(message.data);
} catch (_e) {
// BasicEvaluator already sends RunnerStatus.ERROR; this is a safety net for
// evaluator subclasses that override startEvaluator without the same guarantee.
this.updateStatus(RunnerStatus.ERROR, true);
}
Comment on lines +45 to +49

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The caught error is currently swallowed silently. Swallowing errors makes debugging extremely difficult because the stack trace and error message are lost. It is highly recommended to log the error to console.error so that the failure details are visible in the logs.

            } catch (e) {
                console.error("Evaluator error:", e);
                // BasicEvaluator already sends RunnerStatus.ERROR; this is a safety net for
                // evaluator subclasses that override startEvaluator without the same guarantee.
                this.updateStatus(RunnerStatus.ERROR, true);
            }

}]
]);

Expand Down