Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/four-hoops-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": minor
---

add custom error classes
5 changes: 3 additions & 2 deletions evals/index.eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { EvalLogger } from "./logger";
import { AvailableModel } from "@/dist";
import { env } from "./env";
import dotenv from "dotenv";
import { StagehandEvalError } from "@/types/stagehandErrors";
dotenv.config();

/**
Expand Down Expand Up @@ -226,8 +227,8 @@ const generateFilteredTestcases = (): Testcase[] => {
const taskFunction = taskModule[input.name];

if (typeof taskFunction !== "function") {
throw new Error(
`Task function for ${input.name} is not a function`,
throw new StagehandEvalError(
`No Eval function found for task name: ${input.name}`,
);
}

Expand Down
3 changes: 2 additions & 1 deletion evals/taskConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import fs from "fs";
import path from "path";
import { AvailableModel, AvailableModelSchema } from "@/dist";
import { filterByEvalName } from "./args";
import { UnsupportedModelError } from "@/types/stagehandErrors";

// The configuration file `evals.config.json` contains a list of tasks and their associated categories.
const configPath = path.join(__dirname, "evals.config.json");
Expand Down Expand Up @@ -62,7 +63,7 @@ const getModelList = (): string[] => {
};
const MODELS: AvailableModel[] = getModelList().map((model) => {
if (!AvailableModelSchema.safeParse(model).success) {
throw new Error(`Model ${model} is not a supported model`);
throw new UnsupportedModelError(getModelList(), "Running evals");
}
return model as AvailableModel;
});
Expand Down
7 changes: 5 additions & 2 deletions evals/tasks/peeler_simple.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EvalFunction } from "@/types/evals";
import { initStagehand } from "@/evals/initStagehand";
import { StagehandEnvironmentError } from "@/types/stagehandErrors";

const env: "BROWSERBASE" | "LOCAL" =
process.env.EVAL_ENV?.toLowerCase() === "browserbase"
Expand All @@ -15,8 +16,10 @@ export const peeler_simple: EvalFunction = async ({ modelName, logger }) => {
const { debugUrl, sessionUrl } = initResponse;

if (env === "BROWSERBASE") {
throw new Error(
"Browserbase not supported for this eval since we block all requests to file://",
throw new StagehandEnvironmentError(
"BROWSERBASE",
"LOCAL",
"peeler_simple eval",
);
}

Expand Down
5 changes: 3 additions & 2 deletions examples/external_clients/ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
ChatCompletionUserMessageParam,
} from "openai/resources/chat/completions";
import { z } from "zod";
import { CreateChatCompletionResponseError } from "@/types/stagehandErrors";

function validateZodSchema(schema: z.ZodTypeAny, data: unknown) {
try {
Expand Down Expand Up @@ -226,7 +227,7 @@ export class OllamaClient extends LLMClient {
if (options.response_model) {
const extractedData = response.choices[0].message.content;
if (!extractedData) {
throw new Error("No content in response");
throw new CreateChatCompletionResponseError("No content in response");
}
const parsedData = JSON.parse(extractedData);

Expand All @@ -239,7 +240,7 @@ export class OllamaClient extends LLMClient {
});
}

throw new Error("Invalid response schema");
throw new CreateChatCompletionResponseError("Invalid response schema");
}

return parsedData;
Expand Down
Loading
Loading