Skip to content

Commit f2e0519

Browse files
committed
Fix FileNotFoundError handling in rename_file methods
- Add FileNotFoundError exception handling to both sync and async rename_file methods - Return HTTP 404 error instead of generic 500 error when file/directory doesn't exist - Improves error specificity for file rename operations
1 parent 31a8555 commit f2e0519

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

jupyter_server/services/contents/filemanager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,8 @@ def rename_file(self, old_path, new_path):
602602
shutil.move(old_os_path, new_os_path)
603603
except web.HTTPError:
604604
raise
605+
except FileNotFoundError:
606+
raise web.HTTPError(404, "File or directory does not exist: %s" % old_path)
605607
except Exception as e:
606608
raise web.HTTPError(500, f"Unknown error renaming file: {old_path} {e}") from e
607609

@@ -1069,6 +1071,8 @@ async def rename_file(self, old_path, new_path):
10691071
await run_sync(shutil.move, old_os_path, new_os_path)
10701072
except web.HTTPError:
10711073
raise
1074+
except FileNotFoundError:
1075+
raise web.HTTPError(404, "File or directory does not exist: %s" % old_path)
10721076
except Exception as e:
10731077
raise web.HTTPError(500, f"Unknown error renaming file: {old_path} {e}") from e
10741078

0 commit comments

Comments
 (0)