Skip to content
4 changes: 3 additions & 1 deletion apps/server/src/provider/PiSessionCommands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ describe("Pi session utilities", () => {
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, harness.spawner),
Effect.flip,
);
assert.include(error.message, "gh auth login");
assert.equal(error.message, "Pi RPC share failed: GitHub CLI sharing failed.");
assert.notInclude(error.message, "gh auth login");
assert.isDefined(error.cause);
assert.isFalse(yield* fs.exists(harness.exportPath()));
}).pipe(Effect.provide(NodeServices.layer)),
);
Expand Down
5 changes: 3 additions & 2 deletions apps/server/src/provider/PiSessionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ export const runPiSessionCommand = Effect.fn("runPiSessionCommand")(function* (
}),
).pipe(Effect.timeout("60 seconds"));
if (result.code !== 0) {
const stderr = result.stderr.trim();
return yield* new PiRpcError({
operation: "share",
detail:
result.stderr.trim() || "GitHub CLI sharing failed. Run 'gh auth login' on the server.",
detail: "GitHub CLI sharing failed",
...(stderr.length > 0 ? { cause: new Error(stderr) } : {}),
});
}
const match = /^https:\/\/gist\.github\.com\/(?:[^/\s]+\/)?([\da-f]+)\/?$/i.exec(
Expand Down
7 changes: 6 additions & 1 deletion apps/server/src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6340,7 +6340,12 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
),
);
assert.strictEqual(error._tag, "ProviderSessionCommandError");
assert.include(error.message, "gh auth login on the server");
if (error._tag === "ProviderSessionCommandError") {
assert.strictEqual(error.command, "share");
assert.strictEqual(error.message, "Failed to share provider session.");
assert.notInclude(error.message, "gh auth login on the server");
assert.notProperty(error, "cause");
}
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);

Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2452,7 +2452,7 @@ const makeWsRpcLayer = (
(cause) =>
new ProviderSessionCommandError({
threadId: input.threadId,
detail: cause.message,
command: input.command,
}),
),
),
Expand Down
7 changes: 5 additions & 2 deletions packages/contracts/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ export type ProviderSessionCommandResult = typeof ProviderSessionCommandResult.T

export class ProviderSessionCommandError extends Schema.TaggedError<ProviderSessionCommandError>()(
"ProviderSessionCommandError",
{ threadId: ThreadId, detail: Schema.String },
{
threadId: ThreadId,
command: Schema.Literals(["copy", "export", "share"]),
},
) {
override get message(): string {
return this.detail;
return `Failed to ${this.command} provider session.`;
}
}

Expand Down
Loading