Skip to content

Commit 656db40

Browse files
authored
scripts[patch]: Add notebook check for unexpected rebuild error (#6602)
1 parent 20d5bbe commit 656db40

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import "../dist/validate_notebook.js";
1+
import "../dist/notebooks/index.js";

libs/langchain-scripts/src/validate_notebook.ts renamed to libs/langchain-scripts/src/notebooks/check_notebook_type_errors.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ if (!pathname) {
6969
throw new Error("No pathname provided.");
7070
}
7171

72-
const run = async () => {
72+
export async function checkNotebookTypeErrors() {
7373
if (!pathname.endsWith(".ipynb")) {
7474
throw new Error("Only .ipynb files are supported.");
7575
}
@@ -130,10 +130,4 @@ const run = async () => {
130130
// Do nothing
131131
}
132132
}
133-
};
134-
135-
try {
136-
void run();
137-
} catch {
138-
process.exit(1);
139133
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import fs from "fs";
2+
3+
const [pathname] = process.argv.slice(2);
4+
5+
if (!pathname) {
6+
throw new Error("No pathname provided.");
7+
}
8+
9+
/**
10+
* tslab will sometimes throw an error inside the output cells of a notebook
11+
* if the notebook is being rebuilt. This function checks for that error,
12+
* because we do not want to commit that to our docs.
13+
*/
14+
export async function checkUnexpectedRebuildError() {
15+
if (!pathname.endsWith(".ipynb")) {
16+
throw new Error("Only .ipynb files are supported.");
17+
}
18+
const notebookContents = await fs.promises.readFile(pathname, "utf-8");
19+
if (
20+
notebookContents.includes(
21+
"UncaughtException: Error: Unexpected pending rebuildTimer"
22+
)
23+
) {
24+
throw new Error(`Found unexpected pending rebuildTimer in ${pathname}`);
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { checkNotebookTypeErrors } from "./check_notebook_type_errors.js";
2+
import { checkUnexpectedRebuildError } from "./check_unexpected_rebuild_timer.js";
3+
4+
async function main() {
5+
await Promise.all([checkNotebookTypeErrors(), checkUnexpectedRebuildError()]);
6+
}
7+
8+
try {
9+
void main();
10+
} catch {
11+
process.exit(1);
12+
}

0 commit comments

Comments
 (0)