Skip to content

Commit 2451797

Browse files
include version number in StagehandDefaultError (#807)
# why - for a better debugging experience # what changed - added build step `gen-version.ts` which will read the `package.json` and expose the stagehand version number as a const globally - included the version in the `StagehandDefaultError` message # test plan - regressions
1 parent 9c398bb commit 2451797

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

.changeset/gentle-turtles-stay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
include version number in StagehandDefaultError message

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"build-dom-scripts": "tsx lib/dom/genDomScripts.ts",
2121
"build-types": "tsc --emitDeclarationOnly --outDir dist",
2222
"build-js": "tsup lib/index.ts --dts",
23-
"build": "pnpm run lint && pnpm run build-dom-scripts && pnpm run build-js && pnpm run build-types",
23+
"build": "pnpm run lint && pnpm run gen-version && pnpm run build-dom-scripts && pnpm run build-js && pnpm run build-types",
24+
"gen-version": "tsx scripts/gen-version.ts",
2425
"prepare": "pnpm run build",
2526
"lint": "pnpm run prettier:fix && pnpm run eslint",
2627
"release": "pnpm run build && changeset publish",

scripts/gen-version.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { readFileSync, writeFileSync } from "node:fs";
2+
import { join } from "node:path";
3+
4+
type PackageJson = { version: string };
5+
6+
const pkgPath = join(__dirname, "..", "package.json");
7+
const pkg: PackageJson = JSON.parse(readFileSync(pkgPath, "utf8"));
8+
9+
const fullVersion: `${string}` = pkg.version;
10+
11+
const banner = `/**
12+
* AUTO-GENERATED — DO NOT EDIT BY HAND
13+
* Run \`pnpm run gen-version\` to refresh.
14+
*/
15+
export const STAGEHAND_VERSION = "${fullVersion}" as const;
16+
`;
17+
18+
writeFileSync(join(__dirname, "..", "lib", "version.ts"), banner);

types/stagehandErrors.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ZodError } from "zod";
2+
import { STAGEHAND_VERSION } from "../lib/version.js";
23

34
export class StagehandError extends Error {
45
constructor(message: string) {
@@ -11,7 +12,7 @@ export class StagehandDefaultError extends StagehandError {
1112
constructor(error?: unknown) {
1213
if (error instanceof Error || error instanceof StagehandError) {
1314
super(
14-
`\nHey! We're sorry you ran into an error. \nIf you need help, please open a Github issue or reach out to us on Slack: https://stagehand.dev/slack\n\nFull error:\n${error.message}`,
15+
`\nHey! We're sorry you ran into an error. \nStagehand version: ${STAGEHAND_VERSION} \nIf you need help, please open a Github issue or reach out to us on Slack: https://stagehand.dev/slack\n\nFull error:\n${error.message}`,
1516
);
1617
}
1718
}

0 commit comments

Comments
 (0)