Skip to content

Commit

Permalink
scripts[patch]: Add notebook check for unexpected rebuild error (#6602)
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul authored Aug 22, 2024
1 parent 20d5bbe commit 656db40
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion libs/langchain-scripts/bin/validate_notebook.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import "../dist/validate_notebook.js";
import "../dist/notebooks/index.js";
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ if (!pathname) {
throw new Error("No pathname provided.");
}

const run = async () => {
export async function checkNotebookTypeErrors() {
if (!pathname.endsWith(".ipynb")) {
throw new Error("Only .ipynb files are supported.");
}
Expand Down Expand Up @@ -130,10 +130,4 @@ const run = async () => {
// Do nothing
}
}
};

try {
void run();
} catch {
process.exit(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import fs from "fs";

const [pathname] = process.argv.slice(2);

if (!pathname) {
throw new Error("No pathname provided.");
}

/**
* tslab will sometimes throw an error inside the output cells of a notebook
* if the notebook is being rebuilt. This function checks for that error,
* because we do not want to commit that to our docs.
*/
export async function checkUnexpectedRebuildError() {
if (!pathname.endsWith(".ipynb")) {
throw new Error("Only .ipynb files are supported.");
}
const notebookContents = await fs.promises.readFile(pathname, "utf-8");
if (
notebookContents.includes(
"UncaughtException: Error: Unexpected pending rebuildTimer"
)
) {
throw new Error(`Found unexpected pending rebuildTimer in ${pathname}`);
}
}
12 changes: 12 additions & 0 deletions libs/langchain-scripts/src/notebooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { checkNotebookTypeErrors } from "./check_notebook_type_errors.js";
import { checkUnexpectedRebuildError } from "./check_unexpected_rebuild_timer.js";

async function main() {
await Promise.all([checkNotebookTypeErrors(), checkUnexpectedRebuildError()]);
}

try {
void main();
} catch {
process.exit(1);
}

0 comments on commit 656db40

Please sign in to comment.