fix: propagate CLI stderr in session initialization errors (#65)
This commit is contained in:
@@ -179,8 +179,10 @@ export class Session implements AsyncDisposable {
|
||||
}
|
||||
}
|
||||
|
||||
sessionLog("init", "ERROR: transport closed before init message received");
|
||||
throw new Error("Failed to initialize session - no init message received");
|
||||
const stderr = this.transport.getStderr();
|
||||
const detail = stderr ? `\nCLI stderr:\n${stderr}` : '';
|
||||
sessionLog("init", `ERROR: transport closed before init message received${detail}`);
|
||||
throw new Error(`Failed to initialize session - no init message received${detail}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -198,6 +198,7 @@ export class SubprocessTransport {
|
||||
private agentId?: string;
|
||||
private wireMessageCount = 0;
|
||||
private lastMessageAt = 0;
|
||||
private stderrLines: string[] = [];
|
||||
|
||||
constructor(
|
||||
private options: InternalSessionOptions = {}
|
||||
@@ -247,11 +248,13 @@ export class SubprocessTransport {
|
||||
});
|
||||
|
||||
// Log stderr for debugging (CLI errors, auth failures, etc.)
|
||||
// Also buffer lines so session.initialize() can include them in errors.
|
||||
if (this.process.stderr) {
|
||||
this.process.stderr.on("data", (data: Buffer) => {
|
||||
const msg = data.toString().trim();
|
||||
if (msg) {
|
||||
console.error("[letta-code-sdk] CLI stderr:", msg);
|
||||
this.stderrLines.push(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -356,6 +359,11 @@ export class SubprocessTransport {
|
||||
return this.closed;
|
||||
}
|
||||
|
||||
/** Return buffered stderr output from the CLI subprocess. */
|
||||
getStderr(): string {
|
||||
return this.stderrLines.join("\n");
|
||||
}
|
||||
|
||||
private handleMessage(msg: WireMessage): void {
|
||||
this.wireMessageCount++;
|
||||
this.lastMessageAt = Date.now();
|
||||
|
||||
Reference in New Issue
Block a user