Skip to content

Commit 249f5ed

Browse files
authored
fix: pass through server-v3 operation errors (#1937)
## Summary - return underlying operation error messages from server-v3 streaming handlers - return underlying non-AppError messages from the top-level server-v3 error wrapper - preserve existing status code behavior while making local act/extract/observe 500s diagnosable ## Testing - pnpm --filter @browserbasehq/stagehand-server-v3 typecheck <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Pass through underlying operation errors in `@browserbasehq/stagehand-server-v3` so clients see real failure messages during streaming and top-level responses, and force flow logs on for easier debugging. Status codes stay the same, making local act/extract/observe 500s diagnosable. - **Bug Fixes** - Streaming + error wrapper: return the thrown error’s message for non-`AppError` cases; fall back to a default when not an `Error`, preserving status codes. - Observe route: remove unused `Variables` import/cast to satisfy lint; no behavior change. <sup>Written for commit ba08fd0. Summary will update on new commits. <a href="https://cubic.dev/pr/browserbase/stagehand/pull/1937">Review in cubic</a></sup> <!-- End of auto-generated description by cubic. -->
1 parent 3917df4 commit 249f5ed

5 files changed

Lines changed: 15 additions & 12 deletions

File tree

.changeset/wild-dryers-search.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand-server-v3": patch
3+
---
4+
5+
Improve server-v3 error passthrough for local operation failures

packages/server-v3/src/lib/errorHandler.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ export function withErrorHandling<
6060
return error(reply, err.getClientMessage(), err.statusCode);
6161
}
6262

63-
return error(
64-
reply,
65-
"An internal server error occurred",
66-
StatusCodes.INTERNAL_SERVER_ERROR,
67-
);
63+
const message =
64+
err instanceof Error
65+
? err.message
66+
: "An internal server error occurred";
67+
68+
return error(reply, message, StatusCodes.INTERNAL_SERVER_ERROR);
6869
}
6970
};
7071
}

packages/server-v3/src/lib/stream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export async function createStreamingResponse<TV3>({
192192
const clientMessage =
193193
handlerError instanceof AppError
194194
? handlerError.getClientMessage()
195-
: `${operation ?? "operation"} failed`;
195+
: handlerError.message;
196196

197197
sendData("error", "system", { status: "error", error: clientMessage });
198198

packages/server-v3/src/routes/v1/sessions/_id/observe.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import type { RouteHandlerMethod, RouteOptions } from "fastify";
22
import { StatusCodes } from "http-status-codes";
3-
import type {
4-
Action,
5-
ObserveOptions,
6-
Variables,
7-
} from "@browserbasehq/stagehand";
3+
import type { Action, ObserveOptions } from "@browserbasehq/stagehand";
84
import type { FastifyZodOpenApiSchema } from "fastify-zod-openapi";
95
import { Api } from "@browserbasehq/stagehand";
106

@@ -57,7 +53,6 @@ const observeRouteHandler: RouteHandlerMethod = withErrorHandling(
5753

5854
const safeOptions: ObserveOptions = {
5955
...data.options,
60-
variables: data.options?.variables as Variables | undefined,
6156
model:
6257
typeof data.options?.model === "string"
6358
? { modelName: data.options.model }

packages/server-v3/src/sea-entry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const normalizedArgv = argv[0]?.startsWith("--") ? argv : argv.slice(1);
66

77
// otherwise, start the stagehand/server
88
if (!__internalMaybeRunShutdownSupervisorFromArgv(normalizedArgv)) {
9+
// Force flow logs on before the server module loads Stagehand core.
10+
process.env.BROWSERBASE_FLOW_LOGS = "1";
911
void import("./server.js").catch((err) => {
1012
console.error("Failed to start server:", err);
1113
process.exit(1);

0 commit comments

Comments
 (0)