Skip to content

Commit 3a8ccb4

Browse files
committed
Fail gracefully if notebook not found
1 parent 170f639 commit 3a8ccb4

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

.github/scripts/update_notebook.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,21 @@ def main():
199199
print(f"From branch: {branch_name}")
200200
print(f"Commit prefix: {commit_prefix}")
201201

202+
# Check if notebook file exists
203+
if not notebook_path.exists():
204+
print(f"❌ Notebook file not found: {notebook_path}")
205+
print("This might be expected if the notebook doesn't exist on this branch yet.")
206+
print("Exiting gracefully - no updates needed.")
207+
return
208+
202209
# Load notebook
203-
with open(notebook_path, "r", encoding="utf-8") as f:
204-
notebook = nbformat.read(f, as_version=4)
210+
try:
211+
with open(notebook_path, "r", encoding="utf-8") as f:
212+
notebook = nbformat.read(f, as_version=4)
213+
except Exception as e:
214+
print(f"❌ Failed to read notebook file: {e}")
215+
print("Exiting gracefully - cannot process invalid notebook.")
216+
return
205217

206218
# Setup Jinja environment
207219
jinja_env = jinja2.Environment(
@@ -259,10 +271,13 @@ def main():
259271
print("❌ Failed to find Colab badge cell")
260272

261273
# Save updated notebook
262-
with open(notebook_path, "w", encoding="utf-8") as f:
263-
nbformat.write(notebook, f, version=4)
264-
265-
print("✅ Notebook update complete!")
274+
try:
275+
with open(notebook_path, "w", encoding="utf-8") as f:
276+
nbformat.write(notebook, f, version=4)
277+
print("✅ Notebook update complete!")
278+
except Exception as e:
279+
print(f"❌ Failed to save notebook: {e}")
280+
return
266281

267282

268283
if __name__ == "__main__":

0 commit comments

Comments
 (0)